Use a ssh tunnel to create a simple VPN in OSX to watch country-blocked streaming — via script.

Written by rubas | Published 2016/05/16
Tech Story Tags: ssh | vpn | os-x

TLDRvia the TL;DR App

Sometimes you are at the wrong time at the wrong place.

There is no need for a fancy VPN server when you have access to a ssh server. This could be a machine back at home, a small vps server or even a shared webhosting account.

Tip: Run your own ssh server at port 443 to circumvent any corporate firewall restrictions.

Use SSH Tunnel as a poor man's vpn

ssh -D creates a local SOCKS proxy and forwards all your traffic on this port through the ssh connection.

It is super simple!

$ ssh -D 8000 user@ssh-server.dyndns.org

There is now a SOCKS proxy running under localhost:8000.

Setup a SOCKS proxy in OSX via Terminal

Now you have to configure your network settings to use this SOCKS proxy. Of course we want to automate this for our script.

$ sudo networksetup -setsocksfirewallproxy "Wi-Fi" localhost 8000

Finally we pack everything an a nice script

$ ./tunnel.sh { start | stop }

The end.

Be aware!

Your terminal commands will not use this SOCKS proxy by default. For some (wget, curl..) there is a configuration flag to use a proxy.

But if you want to tunnel all your traffic, you should have a look at sshuttle.

But for me using sshuttle was significantly slower than a simple ssh tunnel. If you run into this problem, try to run sshuttle with the option `--no-latency-control`.


Published by HackerNoon on 2016/05/16