Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I don't know much about proxies in general, and especially not SOCKS5 proxies, so sorry if this is a newbie question but I haven't been able to find the answer online or in the man pages.

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 %h %p
  2. Run ssh -p22 user@remotehost

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

share|improve this question

migrated from Jul 27 '12 at 4:22

This question came from our site for professional and enthusiast programmers.

To make a program whuch does not support SOCKS go through SOCKS, you can use a so-called proxifer; see . In particular, I recommand my open source tun2socks proxifer ( ). – Ambroz Bizjak Jul 26 '12 at 15:34
Thanks for the comment Ambroz. I need it to work in cygwin, and I see from the wikipedia page on proxifiers that all of the ones it mentions are either not implemented in cygwin or not applicable. Is there a way to get a proxifier to work in cygwin? – Rusty Lemur Jul 26 '12 at 15:41
you don't need it to specifically support Cygwin. Cygwin programs are in the end just Windows programs, but with a POSIX interface implemented as a library. If a proxifier works on Windows, it should be able to proxify Cygwin programs just fine. – Ambroz Bizjak Jul 26 '12 at 16:50
Thanks for the info! – Rusty Lemur Jul 26 '12 at 18:15
up vote 11 down vote accepted

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 %h %p

Or simply:

ProxyCommand /usr/bin/nc -x %h %p

I hope it helps.

share|improve this answer
Thanks Saman, that worked! Also, thanks for the explanation, it helps. – Rusty Lemur Jul 26 '12 at 18:19
The ProxyCommand must be the first line of your ~/.ssh/config', or else nested inside a specify Host` section. Not really sure why. It doesn't work if it's the last line in the ~/.ssh/config – Aaron McDaid Jul 14 at 19:21
ssh -o ProxyCommand='nc --proxy-type socks4 --proxy %h %p' user@host

fc19 x86_64, Ncat: Version 6.25

share|improve this answer
just curious - why proxy-type socks4? – suspectus Oct 19 '13 at 9:57
Can you add a little more explanation to this to say why it's the solution. – ChrisF Oct 19 '13 at 10:48
@ChrisF it is the same as accepted solution, but it is one-liner! No need to modify any config file. – j123b567 Dec 2 '15 at 9:39
On Gentoo, right command name is ncat and not nc like on other distros. – j123b567 Dec 2 '15 at 9:40

tsocks ( is a nice wrapper that uses LD_PRELOAD to make any program use SOCKS proxy transparently:

tsocks ssh

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

share|improve this answer

You must log in to answer this question.

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