Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add socks proxy to ssh config file?

Tags:

ssh

I know how to forward SOCKS proxy on the command like below

ssh -D port_number user@host 

This works well but I want to be able to put that forwarding into my SSH config file. But I am not able to locate any useful information or tutorial about.

I have bunch of normal SSH profiles in the config so I prefer to have the forwardings attached to the SSH profiles.

like image 729
yarun can Avatar asked Sep 09 '13 18:09

yarun can


People also ask

Does SSH support SOCKS5?

Create SSH Proxy with SOCKS5 The ssh command provides the -D option in order to create a proxy. The default proxy type is Sock5. Socks5 is a type of HTTP proxy. Also, the local port number should be specified which is listened to on the client system.

What does using SSH as a SOCKS proxy allow?

A SOCKS proxy is an SSH encrypted tunnel in which configured applications forward their traffic down, and then, on the server-end, the proxy forwards the traffic to the general Internet.


2 Answers

Use the config setting "DynamicForward" Here is a quick example of what it should look like:

Host example.com     User username     Port 22     IdentityFile ~/.ssh/id_rsa     DynamicForward 8080 

If the DynamicForward option is only given a port numer it will bind to localhost:port. You can add a specific IP to get it to bind to an address other than the localhost. Using "*:8080" will bind the proxy to all IP addresses on the box. To use an IPv6 address enclose the address in square brackets:

[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080

like image 113
Pete Avatar answered Sep 22 '22 05:09

Pete


I do not recommend use socat because it only support socks4 But you can use ncat

  1. install ncat
  2. add this in your ssh config file ProxyCommand ncat --proxy-type socks5 --proxy 127.0.0.1:1080 %h %p

You may need to check ncat options if it does not work.

like image 36
Yuanmeng Xiao Avatar answered Sep 19 '22 05:09

Yuanmeng Xiao