I’ve been spending a lot of time travelling recently, and one issue I’ve run into is that the free wi-fi on the intercity coach I take does a funny thing with trying to embed ads into HTTP responses. Worse, it does it in a way that breaks some websites. Frustrating. But it only does it to HTTP and not HTTPS, so I decided to take advantage of that by setting up an ssh server on my home network on port 443. I can then use this script to automatically connect and set up the OS X proxy settings, then deactivate the proxy noce disconnected:
#!/bin/sh # Get sudo so we can adjust the network settings [ "$UID" -eq 0 ] || exec sudo bash "$0" "$@" # Tell OS X to connect to a SOCKS proxy on localhost:8080 networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 8080 networksetup -setsocksfirewallproxystate Wi-Fi on echo "SOCKS proxy enabled." # Connect the SSH tunnel, setting it up on localhost:8080 echo "Tunnelling (type Ctrl-C to stop)..." ssh -D 8080 -C -N username@hostname # After they've terminated the SSH session, reset the OS X network settings networksetup -setsocksfirewallproxystate Wi-Fi off echo "SOCKS proxy disabled"