Friday, June 18, 2010

OS X Screen Sharing over SSH

I recently set up a Mac Mini at home, and have found using Screen Sharing to access it invaluable. Not wanting to open up anything other than SSH on my home router, I created the following script to open up a Screen Sharing session over SSH:

#!/bin/sh
# port you have open on your home router to forward ssh
SSH_PORT=22022
# set up dynamic dns if you don't have a static ip
HOST=your.home.ip
# OSX Screen Sharing will complain if you try to connect to the standard
# VNC ports (5900+) on localhost, so pick another available port
LOCAL_PORT=1202
ssh -p $SSH_PORT $HOST -L $LOCAL_PORT:localhost:5900 -f -N
open "vnc://localhost:$LOCAL_PORT"
view raw homevnc.sh hosted with ❤ by GitHub