SSH Proxy – How to Use Socks Proxy for Commands in Terminal like youtube-dl

http-proxyPROXYsocksssh

I connect to a remote ssh server by running this command:

ssh -D 12345 bob@myserver.com

This creates a socks proxy that I can use with Firefox to bypass censorship in my country. However, I can't take advantage of it to in the command line.

Let's say my country blocks access to youtube. How can I use the ssh connection to run a command such as:

youtube-dl "youtube.com/watch?v=3XjwiV-6_CA"

Without being blocked by the government? How I can set a socks proxy for all terminal commands?

Best Answer

Youtube-dl doesn't support a SOCKS proxy. There's a feature request for it, with links to a couple of working proposals.

Youtube-dl supports HTTP proxies out of the box. To benefit from this support, you'll need to run a proxy on myserver.com. Pretty much any lightweight proxy will do, for example tinyproxy. The proxy only needs to listen to local connections (Listen 127.0.0.1 in tinyproxy.conf). If the HTTP proxy is listening on port 8035 (Port 8035), run the following ssh command:

ssh -L 8035:localhost:8035 bob@myserver.com

and set the environment variables http_proxy and https_proxy:

export http_proxy=http://localhost:8035/ https_proxy=http://localhost:8035/
youtube-dl youtube.com/watch?V=3XjwiV-6_CA