First, I setup a private/public keypair and created an entry for my home network using a Dynamic DNS address I have setup (all addresses have been changed to protect the idiotic):
$ cat .ssh/config
Forward local ports
Next, I forwarded local port 8087 to port 80 on one of my internal boxes, and local port 15900 to port 5900 (VNC) on another:
ssh -L 8087:192.168.1.2:80 -L 15900:192.168.1.10:5902 home
Voila, now I can browse to http://127.0.0.1:8087 and access the home server, and pull up the desktop using /System/Library/CoreServices/Applications/Screen Sharing.app on the Mac:
Next step was to automate keeping the tunnel open. I use brew to manage “Unix-style” packages on macOS - highly recommended.
$ brew install autossh
$ cat StartSSHTunnel.command
autossh -M 0 -N -f -q -L -L 8087:192.168.1.2:80 -L 15900:192.168.1.10:5902 \
-o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=no \
-o BatchMode=yes home
And that’s it! It’s not quite as elegant or seamless as having a properly functioning VPN, but I got it up and running in about 5 minutes, vs. banging my head against the wall trying to troubleshoot why Viscosity can’t seem to connect to the router.