Thursday, September 13, 2012

A Serial Console on OSX

A lot of times I find myself needing to recover passwords on old routers and switches that the world has forgotten about (along with their passwords, hence the password recovery).  It was easy in my PC days to simply fire up HyperTerm and go, and most Linux distributions still come with Minicom, if you know where to look.  But OSX is different.  There are 3rd party apps available, and I used zTerm for a while, but then I found you could simply use the OSX terminal app and a couple of quick commands to get a very capable, tabbed environment for mixing console and SSH access to a bunch of devices.  Perfect!

So you will need to start with a USB-to-Serial adapter that's supported by OSX.  I've had lots of success with PL2303 variants, so look for that chip in your adapter of choice.  Once you have it, plug it in and run the following command and watch the output:


bigmac:~ greg$ ls -l /dev/tty.*
crw-rw-rw-  1 root  wheel   18,   2 Sep 13 06:03 /dev/tty.Bluetooth-Modem
crw-rw-rw-  1 root  wheel   18,   0 Sep 13 06:03 /dev/tty.Bluetooth-PDA-Sync
crw-rw-rw-  1 root  wheel   18,   4 Sep 13 09:28 /dev/tty.PL2303-00001004

Now unplug the adapter and repeat:

bigmac:~ greg$ ls -l /dev/tty.*
crw-rw-rw-  1 root  wheel   18,   2 Sep 13 06:03 /dev/tty.Bluetooth-Modem
crw-rw-rw-  1 root  wheel   18,   0 Sep 13 06:03 /dev/tty.Bluetooth-PDA-Sync

Notice the entry that went away?  That's my adapter's device name.  In my case the naming was pretty obvious, but that may not always be the case.

Anyway, now that I know the name of my device, I can plug it back in and use the screen utility to open up a console session:

gbensimon-sslvpn-nc:~ greg$ screen /dev/tty.PL2303-00001004 9600

This will open a session at 9600 bps via my USB-to-Serial adapter.  Once engaged, A-? will bring up a useful help screen:

                       Screen key bindings, page 1 of 1.

                       Command key:  ^A   Literal ^A:  a

  break       ^B b         license     ,            reset       Z         
  clear       C            lockscreen  ^X x         screen      ^C c      
  colon       :            log         H            select      '         
  copy        ^[ [         meta        a            silence     _         
  detach      ^D d         monitor     M            split       S         
  digraph     ^V           next        ^@ ^N sp n   suspend     ^Z z      
  displays    *            number      N            time        ^T t      
  dumptermcap .            only        Q            title       A         
  fit         F            other       ^A           vbell       ^G        
  flow        ^F f         pow_break   B            version     v         
  focus       ^I           pow_detach  D            width       W         
  hardcopy    h            prev        ^H ^P p ^?   windows     ^W w      
  help        ?            quit        ^\           wrap        ^R r      
  history     { }          readbuf     <            writebuf    >         
  info        i            redisplay   ^L l         xoff        ^S s      
  kill        ^K k         remove      X            xon         ^Q q      
  lastmsg     ^M m         removebuf   =         

^]  paste .
"   windowlist -b
-   select -
0   select 0
1   select 1
2   select 2
3   select 3
4   select 4
5   select 5
6   select 6
7   select 7
8   select 8
9   select 9
]   paste .


                        [Press Space or Return to end.]

You'll see it's pretty full-featured.

I've been using this since the Tiger (10.4) days.  I had some issues with Snow Leopard (10.6) and 64-bit support, but updated drivers seem to have resolved the problems.  I'm currently on Mountain Lion (10.8), and it's still working great.

1 comment:

  1. And just to make launching easier, I created an alias called "console96" that executes 'screen /dev/tty.PL2303-00001004 9600' for me.

    ReplyDelete