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):
- On the Mac, enable ssh remote logins. This is done in
System Preferences->Sharingpanel and checking the box for the
- Again on the Mac, set-up to allow password-free logins (put your public key in
- On the FreeBSD machine add an entry in your
~/.ssh/configfile 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.
- Enable VNC on the Mac in the same
System Preferences->Sharingpanel by checking the box for
Screen Sharingservice 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.
- Run the VNC client on the FreeBSD machine like this:
vncviewer -via mymac localhost
-via switch does is run ‘
/usr/bin/ssh -f -L 5599:localhost:5900 mymac sleep 20’ which sets up an ssh tunnel to
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.