A simple Python script that creates an SHH tunnel and uses “networksetup” on Mac OS X to create a SOCKS proxy using the tunnel. Simply run the script in a terminal window with a command line option telling it which network interface you’d like to use the tunnel with (e.g. “Wi-Fi”, “Ethernet”, etc). The script will continue running and to end the tunnel simply quit with Control+C. The script also nicely resets your network settings if the SSH tunnel closes due to a lose of network connectivity, which is nice when moving a laptop from home to work. I created this after after upgrading to Mac OS 10.7 and having an issue with SSHTunnel, which is otherwise a great program.
For Mac OS 10.8+, the security settings have changed and the program “networksetup”, which is run by the setproxy.py script, requires admin privileges. To fix this, I've included the "sudo" command in the script. By default, this will bring up a ridiculous number of dialog boxes asking for your password. To avoid these, you need to add the command "networksetup" to the "sudoers" file with the "NOPASSWORD" option so that you can always run that command as root without a password. To do this,
- Edit the sudoers files by typing
- Create a new line that looks like the following replacing "vancleve" with your username:
vancleve ALL=(root) NOPASSWD: /usr/sbin/networksetup
- Save the file and exit.