What is the difference between the following?

Host foo
    ProxyCommand ssh example.com -- /usr/bin/nc %h %p 2> /dev/null


Host foo
    ProxyCommand ssh -W %h:%p example.com

Which one should I prefer when? Is either of them faster or more efficient in some way?


The two settings do the same thing. The -W option was added in 2010 and is described as a “netcat mode”.

Use ssh -W if you don't need compatibility with versions of OpenBSD prior to 4.7 or with portable OpenSSH prior to 5.5 (I think). Use nc if you do need to support older versions of OpenSSH. ssh -W is preferable if available because it's marginally more efficient and doesn't require a separate utility to be installed.

  • Use -W whenever available, our gateway somehow had a lot of nc instances spinning even if the SSH connection to the gateway was gone.
    – Lekensteyn
    Nov 9 '14 at 10:35

Using ssh directly will always be marginally faster because you're not calling out to the external nc binary, and it should be preferred because there's no guarantee nc exists on the target system.

  • That's what common sense tells me too, but then it makes me wonder why I see so many sites suggesting the first one instead of the second one.
    – user541686
    Nov 9 '14 at 8:44

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.