Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
I found a temporary solution. I've used tsocks. Once installed, when the ssh connection is established, I launch the application I want with tsocks as follows: tsocks gnome-terminal – user1098135 Apr 9 '13 at 4:08
up vote 7 down vote accepted

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 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
share|improve this answer
if they are going to use SSH then why do they need tinyproxy or vice versa? I use SSH tunnel and it works fine. – Neutralizer Sep 14 '14 at 9:54
@Neutralizer SSH only relays from the local machine to the proxy machine. Something on the proxy machine needs to decode the HTTP request and figure out the IP address of the server machine. If the client supports SOCKS then SSH can do the job, but youtube-dl doesn't support SOCKS. If you're using the proxy for a specific server, you may be able to use SSH alone and tell it to forward directly to that server, but that only works if all the requests need to be forwarded to the same IP address and port. – Gilles Sep 14 '14 at 12:06
For debugging it is nice to run the ssh command with -v and to skip the interactive session one can also add -N. – fikovnik Jun 8 '15 at 21:17
ssh -D 8080 name@myserver.com

export http_proxy=socks5:// https_proxy=socks5://

youtube-dl youtube.com/watch?V=3XjwiV-6_CA
share|improve this answer
simple and works for me. – Kevin Tong Mar 7 '15 at 13:05
add -N to skip the interactive ssh session – fikovnik Jun 8 '15 at 21:19

You can use Delegate,

It's a SOCKS server and/or client that can listen as HTTP proxy.

Download latest version of delegate and extract it.

First run your ssh command:

ssh -D 9150 me@myserver.com

Then, run binary delegate file with these options to have a HTTP proxy as a SOCKS client:

$ ./dg9_9_13 -P8080 SERVER=http SOCKS= ADMIN="local@localhost.com"

Then, run youtube-dl with --proxy option to connect to listened HTTP proxy:

$ youtube-dl -v --proxy "" https://www.youtube.com/watch?v=VID
share|improve this answer

If Youtube videos are what you are after, you might want to try cclive, which seems to support proxies. And it can do other streaming sites as well.

share|improve this answer

youtube-dl works well with proxychains on ubuntu. Make sure ur tunneling via command line.

ssh -D 8081 ubuntu@yourSSHserver

next install proxychains on your localhost not the ssh server ur conncted to.

sudo apt-get install proxychains

edit your proxychains config file

sudo nano /etc/proxychains.conf

edit the port number on the last line

socks4 8081

Note:I'm using proxychains on port 8081

then just add proxychains to the begining of the command when using youtube-dl

proxychains ./youtube-dl http://thesite.com/yourvideo.hmtl 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.