Jun 292010
 

I’ve been using vncviewer (on FreeBSD) to run a VNC client that connects to my MacBookPro (usually sitting not far from me) since KVMs supporting USB and DVI are pretty flaky (at least the few I’ve tried). Anyway, I finally bothered to figure out how to run it via an ssh-tunnel.

This ended up being easier than I thought it would be. Here’s what I needed to do (note that steps 1-3 have nothing to do with VNC, only ssh):

  1. On the Mac, enable ssh remote logins. This is done in System Preferences->Sharing panel and checking the box for the Remote Login service.
  2. Again on the Mac, set-up to allow password-free logins (put your public key in ~/.ssh/authorized_keys)
  3. On the FreeBSD machine add an entry in your ~/.ssh/config file to ease ssh connections to the Mac. Something like this:
    Host mymac
      HostName mymac.example.com
      User myuid
      IdentityFile ~/.ssh/id_rsa
      IdentitiesOnly yes

    Then test it by ssh’ing into the Mac from the FreeBSD machine.

  4. Enable VNC on the Mac in the same System Preferences->Sharing panel by checking the box for Screen Sharing service and set a password using the ‘Computer Settings...” button. I think the ‘Remote Management’ service does a similar thing (uses VNC at least), but I’m not sure of the exact differences.
  5. Run the VNC client on the FreeBSD machine like this:
    vncviewer -via mymac localhost

What that -via switch does is run ‘/usr/bin/ssh -f -L 5599:localhost:5900 mymac sleep 20’ which sets up an ssh tunnel to mymac through localhost, that vncviewer then uses by connecting to localhost. You’ll have to use that tunnel (i.e. finish logging in) in the first 20 secs, but once connected it will stay there until you close the VNC session.

 Posted by at 4:35 pm  Tagged with: ,