I’m working in a coffee shop today. I used SSH and SOCKS to browse the Internet securely, but today I decided to take it a step further and automate the process with a shell script. Here’s the script, for what it’s worth:
#!/bin/bash disable_proxy() { networksetup -setsocksfirewallproxystate Wi-Fi off networksetup -setsocksfirewallproxystate Ethernet off echo "SOCKS proxy disabled." } trap disable_proxy INT networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 9999 networksetup -setsocksfirewallproxy Ethernet 127.0.0.1 9999 networksetup -setsocksfirewallproxystate Wi-Fi on networksetup -setsocksfirewallproxystate Ethernet on echo "SOCKS proxy enabled." echo "Tunneling..." ssh -ND 9999 MYHOST.macminicolo.net
Instructions:
- Save this to a file. I saved it to “/Users/richard/bin/ssh_tunnel”.
- Make it executable and run it.
$ chmod a+x /Users/richard/bin/ssh_tunnel $ /Users/richard/bin/ssh_tunnel
- It creates an SSH tunnel to my dedicated server at macminicolo.net and routes Internet traffic through that server.
- Hit Control-C to quit. The proxy is disabled. No need to fiddle with Network Preferences manually.
UPDATE March 18, 2011: I haven’t tried it, but Sidestep appears to be a free Mac OS X app that will enable SSH tunneling automatically when you connect to an insecure network.