Skip to content

Instantly share code, notes, and snippets.

@jbott
Created May 29, 2013 17:54
Show Gist options
  • Save jbott/5672278 to your computer and use it in GitHub Desktop.
Save jbott/5672278 to your computer and use it in GitHub Desktop.
Automatically create a ssh socks proxy and turn it on in network settings
#!/bin/sh
#######################################
#Remote settings
USER=USERNAME
HOST=HOSTNAME
PORT=22
#Local settings
INAME=Wi-Fi
LPORT=8080
#######################################
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
echo "Starting proxy..."
ssh -ND $LPORT $USER@$HOST -p $PORT & < /dev/null
SSH_PID=$!
networksetup -setsocksfirewallproxystate $INAME on
echo "Started."
read -p "Press any key to close."
networksetup -setsocksfirewallproxystate $INAME off
kill $SSH_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment