SSH is an awesome tool that is useful for a lot more things than it was created for. One of the most useful features is the ability to setup a quick proxy server, this works nice for simple tricks, like punching out of a restrictive firewall if you can SSH into another computer outside of that firewall.
The issue with the above method is that it's very simple for the most generic cases out there. There is a more general method to allow you to get around a restrictive firewall which is to setup a SOCKS proxy server for both the browser and terminal. Again SSH to the rescue:
ssh -D 1080 [email protected]
After running this command you just need to configure your browsers to use SOCKS configuration with the address of localhost
and the port of 1080
as defined above.
This is great and all for the browser, but how do you use this with CLI tools. Well there is a an environmental variable called socks_proxy
that tools like git
and curl
will honor. If you have a tool that doesn't support the socks_proxy
environmental variable then you'll have to use a different tool to help you setup the SOCKS proxy in the command line. If you do have the a tool that supports the socks_proxy
environmental variable then this is how you'd use it.
socks_proxy=localhost:1080 curl google.com
will run the curl request through the SOCKS proxy that you previously setup.