Skip to content

Instantly share code, notes, and snippets.

@frank-who
Created November 14, 2012 21:18
Show Gist options
  • Save frank-who/4074899 to your computer and use it in GitHub Desktop.
Save frank-who/4074899 to your computer and use it in GitHub Desktop.
Configure proxies in OSX and open an SSH tunnel
# Usage: bash ergo-proxy.sh <on off>
# Hitting ctrl-c while tunneled will exit the tunnel and turn the proxies off
STATE=$1
# Get a list of network services: networksetup -listallnetworkservices
NETWORKSERVICE=Wi-Fi
# Local port
PORT=3128
# Remote host
HOST=localhost
# Remote host port
HOST_PORT=8888
# SSH connection string
CONNECTION="$HOME/.ssh/kp-xxx.pem ubuntu@ec2-X-X-X-X.compute-1.amazonaws.com"
########################################################################
sudo echo 'Sudo Up!'
proxy_on() {
echo 'Proxy On'
sudo networksetup -setwebproxy $NETWORKSERVICE $HOST $PORT
sudo networksetup -setsecurewebproxy $NETWORKSERVICE $HOST $PORT
ssh -L $PORT:$HOST:$HOST_PORT -N -i $CONNECTION
}
proxy_off() {
echo 'Proxy Off'
sudo networksetup -setwebproxystate $NETWORKSERVICE off
sudo networksetup -setsecurewebproxystate $NETWORKSERVICE off
}
control_c() {
echo '* Exiting'
proxy_off
exit $?
}
trap control_c INT
if [[ $STATE = 'on' || $STATE = '' ]]; then
proxy_on
elif [[ $STATE = 'off' ]]; then
proxy_off
fi
@imgarylai
Copy link

Hi, I read your article about set proxy server on aws ec2. However, I followed your article step by step. It still can't establish proxy server.
After this step : ssh -L 3128:localhost:8888 -N -i ~/.ssh/kp-ergo-proxy.pem ubuntu@ec2-184-169-221-31.us-west-1.compute.amazonaws.com
Should I see anything on my terminal ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment