Windows – OpenSSH config file on Windows – ProxyCommand not working

opensshport-forwardingremote accesssshwindows

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

Best Answer

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!

Related Question