Skip to content

Instantly share code, notes, and snippets.

@flash1293
Last active October 12, 2018 18:40
Show Gist options
  • Save flash1293/210d759ed684dd45b6f3 to your computer and use it in GitHub Desktop.
Save flash1293/210d759ed684dd45b6f3 to your computer and use it in GitHub Desktop.
Enable/disable ssh SOCKS proxy tunnel on mac

To create a SOCKS proxy which tunnels all of your traffic through ssh, you have to go to System preferences > Network > Wi-fi > Proxies > SOCKS-Proxy

Here enter localhost as host and 8080 as port. Don't enable the checkbox, at SOCKS-Proxy, the script takes care of that.

Create the file tunnel.sh and make it executable (chmod +x tunnel.sh). To establish the connection, run ./tunnel.sh - now everything uses the ssh-tunnel. To kill it, press ctrl + C.

This is useful to hop on a trusted environment in public wifis.

#!/bin/bash
#creates a socks-proxy via ssh-tunnel for fast internet-access
#turn on proxy
sudo networksetup -setsocksfirewallproxystate Wi-Fi on
#create tunnel (this is blocking)
ssh -D 8080 -C -N <USER>@<HOST>
#turn off proxy
sudo networksetup -setsocksfirewallproxystate Wi-Fi off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment