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?

kenorb
  • 20,250
  • 14
  • 140
  • 164
user1098135
  • 603
  • 1
  • 6
  • 5
  • 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 09 '13 at 04: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

7 Answers7

86
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"
kenorb
  • 20,250
  • 14
  • 140
  • 164
amidevous
  • 861
  • 1
  • 6
  • 2
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
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 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 09: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 08 '15 at 21:17
  • 1
    [SOCKS proxy support has been added to `youtube-dl` on 2016.05.10](https://github.com/rg3/youtube-dl/issues/402#issuecomment-218187016). – kenorb Apr 09 '18 at 19:00
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 
Saeed AlFalasi
  • 151
  • 1
  • 3
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
Omid Raha
  • 151
  • 1
  • 2
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/.

kenorb
  • 20,250
  • 14
  • 140
  • 164
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.

refik
  • 101
  • 1
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.

peterph
  • 30,520
  • 2
  • 69
  • 75