5

I am trying to use OpenSSH ProxyCommand on Windows to connect to device2 through device1. Device2 requests xxxxx port forwarding and connection without ProxyCommand works fine (but requires first connecting to device1 and then device2, and I want easy, one step connection).

I've created C:\Program Files\OpenSSH\etc\ssh_config file as following:

Host device1
Hostname xxx.xxx.xx.xx
User root

Host device2
ProxyCommand ssh -q device1 nc -q0 localhost xxxxx

Now when I type

ssh user@device2

I get

/bin/sh: No such file or directory
write: Broken pipe

I have checked this on Linux OS and it worked just fine. Could you please explain what might me wrong?

Additionally I've also tried creating config in C:\Program Files\OpenSSH\home\user\.ssh\config and got the same result.

When I delete config file then I get

ssh: Could not resolve hostname device2: Name or service not known

So the file seems to be detected.

I am using OpenSSH_7.6p1, OpenSSL 1.0.2k 26 Jan 2017, and Windows 10

9
  • 1
    You need to specify what Windows build of OpenSSH are you using. There are many. Jan 8, 2018 at 12:15
  • OpenSSH_7.6p1, OpenSSL 1.0.2k 26 Jan 2017, and Windows 10. Added to question
    – Jacek
    Jan 8, 2018 at 12:20
  • That's not an answer to my question (while still a useful information). I'm asking where did you get Windows build of OpenSSH. Jan 8, 2018 at 12:46
  • I think its from here sourceforge.net/projects/sshwindows Reading the reviews I think it was bad choice. If that is not the file I used then I can't find the original link.
    – Jacek
    Jan 8, 2018 at 13:12
  • Also, after some time I used Windows Optional Features and installed OpenSSH Client (Beta). Thought it would solve my problem
    – Jacek
    Jan 8, 2018 at 13:25

5 Answers 5

5

I fought with this today beacuse I wanted to use ProxyJump in Windows. The problem seems to be that the openssh in Windows might call the wrong ssh which did not work for me.

λ ssh.exe -v target-via-pj
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Reading configuration data C:\\Users\\nico/.ssh/config
debug1: C:\\Users\\nico/.ssh/config line 41: Applying options for target-via-pj
debug1: Setting implicit ProxyCommand from ProxyJump: ssh -v -W '[%h]:%p' my-proxy
debug1: Executing proxy command: exec ssh -v -W '[XXX.XXX.XXX.XXX]:22' my-proxy
CreateProcessW failed error:2
posix_spawn: No such file or directory

What works for me is specifying the ProxyCommand explicitly. Here is my definition in Windows of my proxy and target.

Host my-proxy
        HostName 192.168.66.22                 
        User user                              
        IdentityFile ~/.ssh/id_rsa

Host target-via-pj
          Hostname XXX.XXX.XXX.XXX          
          User user
          ProxyCommand ssh.exe -W %h:%p proxy
          IdentityFile ~/.ssh/id2_rsa     

This leads to:

λ ssh.exe -v target-via-pj                                                                      
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5                                                     
debug1: Reading configuration data C:\\Users\\nico/.ssh/config                               
debug1: C:\\Users\\nico/.ssh/config line 41: Applying options for target-via-pj                
debug1: Executing proxy command: exec ssh.exe -W XXX.XXX.XXX.XXX:22 proxy
debug1: key_load_public: No such file or directory                                            
debug1: identity file C:\\Users\\nico/.ssh/id_rsa type -1                                  
debug1: key_load_public: No such file or directory                                            
debug1: identity file C:\\Users\\nico/.ssh/id_rsa-cert type -1                             
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7                                  
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.3  
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH* compat 0x04000000                 
debug1: Authenticating to XXX.XXX.XXX.XXX:22 as 'user'                                       

Hope that helps!

1

With Windows 10 1903 and https://nmap.org/, ProxyCommand should work fine, i think you can do this now, below is sample command for HTTP proxy, hope this can give some help,

ssh [email protected] -o "ProxyCommand C:\Program Files (x86)\Nmap\ncat.exe --verbose --proxy-type http --proxy 127.0.0.1:10801 %h %p" -v

Full log:

C:\Users\xxx>ssh xxx.xxx -p 22 -o "ProxyCommand C:\Program Files (x86)\Nmap\ncat.exe --verbose --proxy-type http --proxy 127.0.0.1:10801 %h %p" -v
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Reading configuration data C:\\Users\\xxx/.ssh/config
debug1: C:\\Users\\xxx/.ssh/config line 2: Applying options for xxx.xxx
debug1: Executing proxy command: exec C:\\Program Files (x86)\\Nmap\\ncat.exe --verbose --proxy-type http --proxy 127.0.0.1:10801 xxx.xxx 22
5
  • (1) Really? You don’t need to quote or escape the space in the filename? (2) I don’t see how this can be an answer to the question when it doesn’t mention device1 or device2. Jun 23, 2019 at 2:23
  • @Scott, check update, 1) I upload full log. 2)I don't have two machine to test OP, when i met how to use HTTP proxy in window open ssh issue, i search into this question, after i solved this, i think i can give some hit to OP, show ProxyCommand work fine.
    – zizifn
    Jun 23, 2019 at 5:18
  • I was looking for this syntax, this answer helped me. I don't know why it was downvoted.
    – user13756
    Feb 5, 2021 at 19:35
  • This works pretty well! Now how do I use this in the ssh config? so I don't have to provide the -o parameter every single time I ssh?
    – Shayan
    Aug 6, 2023 at 8:33
  • add below line into config: ProxyCommand ncat --verbose --proxy-type http --proxy 127.0.0.1:4081 %h %p
    – zizifn
    Aug 6, 2023 at 8:41
0

Ok so I think I figured this out, although my problem is not solved, as it can't be.

From my research and thanks to https://superuser.com/users/213663/martin-prikryl I learned that there is no build of OpenSSH for Windows with support of ProxyCommand (at least I couldn't find one, and on their site is such info).

The reason I got:

/bin/sh: No such file or directory
write: Broken pipe

Was because of bad OpenSSH build. I downloaded it from

https ://sourceforge.net/projects/sshwindows/

And according to the reviews there, this build is broken! Please do not use it! After I uninstalled this OpenSSH and installed official one from the website (or from Windows 10 optional functions) I got correct error:

Proxy connect is not supported in Windows yet
0

For Windows needed to use ssh.exe. At least for the moment.

Host device2
ProxyCommand ssh.exe -q device1 nc -q0 localhost xxxxx
0

I use both HTTP proxy and socks5 proxy for git with connect.exe on Windows, and both work.

Host  company
  HostName  dest.company.com
  User git
  ProxyCommand connect -H mydomain.com:10001 %h %p

For your case, the following maybe works

Host device1
    Hostname xxx.xxx.xx.xx
    User root

Host device2
    ProxyCommand ssh device1 connect %h %p 

Just check this clue, https://github.com/gotoh/ssh-connect?tab=readme-ov-file#break-the-more-restricted-wall

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 25 at 17:13

You must log in to answer this question.

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