70

I have a SOCKS5 proxy set up through PuTTY with port 7777 configured as a dynamic port. I can use firefox/filezilla/etc by configuring them to use a SOCKS proxy with localhost and port 7777. But I can't figure out how to ssh (through Cygwin) to a remote server by using the dynamic port. Is this possible?

I've tried using ProxyCommand via the following method.

  1. Create ~/.ssh/config with the following line:

    ProxyCommand /usr/bin/nc -X connect -x 127.0.0.1:7777 %h %p
    
  2. Run ssh -p22 user@remotehost

The message I get is ssh_exchange_identification: Connection closed by remote host

Braiam
  • 4,777

6 Answers6

71

You are using 'connect' for HTTPS as your proxy version, this is from man nc:

-X proxy_version Requests that nc should use the specified protocol when talking to the proxy server. Supported protocols are ''4'' (SOCKS v.4), ''5'' (SOCKS v.5) and 'connect' (HTTPS proxy). If the protocol is not specified, SOCKS version 5 is used.

So you should use the following to use SOCKS 5:

ProxyCommand /usr/bin/nc -X 5 -x 127.0.0.1:7777 %h %p

Or simply:

ProxyCommand /usr/bin/nc -x 127.0.0.1:7777 %h %p

I hope it helps.

18
ssh -o ProxyCommand='nc --proxy-type socks4 --proxy 127.0.0.1:9050 %h %p' user@host

fc19 x86_64, Ncat: Version 6.25

8

tsocks (http://tsocks.sourceforge.net/) is a nice wrapper that uses LD_PRELOAD to make any program use SOCKS proxy transparently:

tsocks ssh example.com

Just works, remember to configure SOCKS proxy IP in /etc/tsocks.conf

neutrinus
  • 189
  • 1
  • 3
3

Just to make it more simple, you could put these in ~/.ssh/config

host = example.com
ProxyCommand nc -X 5 -x 127.0.0.1:9150 %h %p

Any ssh command in terminal will now get through this proxy.

azerafati
  • 131
2

This following command will do, to just use nc:

ssh examplehost.com -o "ProxyCommand=nc --proxy localhost:7000 %h %p"

Default is HTTP proxy, there is an HTTP proxy running on port 7000.

2

ssh is able to understand ALL_PROXY environment variable so apparently something like this

ALL_PROXY=socks5://127.0.0.1:9150 ssh example.com

does the trick also for me at least.