60

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

ssh -D 12345 [email protected]

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?

2
  • 1
    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 Commented Apr 9, 2013 at 4:08
  • 1
    tsocks youtube-dl ... - tsocks is a clever application, commonly available in repositories, that uses LD_PRELOAD to force applications to route their traffic through a designated SOCKS connection (specify which in ~/.tsocks.conf).
    – Zaz
    Commented Jun 23, 2018 at 23:17

7 Answers 7

88
ssh -D 8080 [email protected]
export http_proxy=socks5://127.0.0.1:8080 https_proxy=socks5://127.0.0.1:8080
youtube-dl "youtube.com/watch?V=3XjwiV-6_CA"
4
  • simple and works for me.
    – Kevin Tong
    Commented Mar 7, 2015 at 13:05
  • 8
    add -N to skip the interactive ssh session
    – fikovnik
    Commented Jun 8, 2015 at 21:19
  • 1
    How do I make applied to all protocol or general protocol such as UDP and TCP instead of only http and https? Commented Feb 6, 2022 at 8:55
  • i get Unsupported scheme 'socks5' error Commented Feb 10, 2023 at 9:19
28

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 [email protected]

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
4
  • if they are going to use SSH then why do they need tinyproxy or vice versa? I use SSH tunnel and it works fine.
    – Umair A.
    Commented Sep 14, 2014 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. Commented Sep 14, 2014 at 12:06
  • 1
    For debugging it is nice to run the ssh command with -v and to skip the interactive session one can also add -N.
    – fikovnik
    Commented Jun 8, 2015 at 21:17
  • 1
15

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  127.0.0.1 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 
1
  • proxychains is a cool tool Commented May 1, 2017 at 7:32
5

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 [email protected]

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

$ ./dg9_9_13 -P8080 SERVER=http SOCKS=127.0.0.1:9150 ADMIN="[email protected]"

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

$ youtube-dl -v --proxy "http://127.0.0.1:8080" https://www.youtube.com/watch?v=VID
3

Since youtube-dl version 2016.05.10, you can use --proxy to specify SOCKS proxy, e.g.

youtube-dl --proxy "socks5://127.0.0.1/" -v 9bZkp7q19f0

--proxy URL Use the specified HTTP/HTTPS/SOCKS proxy. To enable experimental SOCKS proxy, specify a proper scheme. For example socks5://127.0.0.1:1080/.

0

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.

0

You can also use polipo to create an http proxy and use your socks5 proxy as the parent proxy.

$ polipo socksParentProxy=127.0.0.1:12345 # change accordingly
Established listening socket on port 8123

Now, you can use 127.0.0.1:8123 as an http proxy with any command-line tool that supports it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .