43

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?

  • 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 – user1098135 Apr 9 '13 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 Jun 23 '18 at 23:17
23

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
| 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. – Umair A. 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 'SO- stop being evil' Sep 14 '14 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 Jun 8 '15 at 21:17
  • 1
59
ssh -D 8080 name@myserver.com
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"
| improve this answer | |
  • simple and works for me. – Kevin Tong Mar 7 '15 at 13:05
  • 5
    add -N to skip the interactive ssh session – fikovnik Jun 8 '15 at 21:19
9

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 
| improve this answer | |
  • proxychains is a cool tool – 2 8 May 1 '17 at 7:32
2

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=127.0.0.1:9150 ADMIN="local@localhost.com"

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
| improve this answer | |
1

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/.

| improve this answer | |
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.

| improve this answer | |
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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