SOCKS proxy with OpenSSH (instead of port forwarding)

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

You’ve probably used port forwarding available in OpenSSH to securely forward selected ports to selected hosts.

What if you wanted to securely push i.e. all web traffic from your PC/laptop through some other server running?

OpenSSH and its SOCKS capability to the rescue!

Simply run this on your PC/laptop:

ssh -D 10800 -N -C -v remote_ssh_server

where:

-D 10800 - SOCKS server started by OpenSSH, will listen on port 10800 on localhost
-N - do not execute any command, leaves ssh process in foreground
-C - compress all traffic
-v - be verbose

Then, set your browser (or some other program) to use a SOCKS proxy at 127.0.0.1, port 10800, and all traffic will flow through your server.

If you have any command line programs which don’t support SOCKS natively, you can use torsocks tool.