Problems with SSH ProxyCommand execution

I'm following this resource to set up something like a proxy server for ssh

My setup is exactly like the mention in the post:

Remote Server A
Machine-1
Machine-2

Machine-1 is the bastion server from which I can ssh to the remote server (using identity file)

Machine-2 can connect to Machine-1 using a password.

Requirement:

Connect to Remote Server(A) from Machine-2 via Machine-1

Machine-2 <--> Machine-1 <--> Remote Server(A)

Here how my command looks (running this command from machine-2)

ssh -o "ProxyCommand=ssh -W user2@%h:%p user1@machine-1" user2@remote_server 

But I yet to see the success.

The error I see on the

channel 0: open failed: connect failed: nodename nor servname provided, or not known
stdio forwarding failed
kex_exchange_identification: Connection closed by remote host 

I don't this often so I'm not sure what is wrong. But according to the resource the step done looks correct to me.


You don't need the user2@ part in your ProxyCommand. This should work:

ssh -o "ProxyCommand=ssh -W %h:%p user1@machine-1" user2@remote_server

However, it might be easier to write a config for this. Also, if you use ProxyJump instead of ProxyCommand, the config will be easier to read. Write these lines to your ~/.ssh/config file:

Host machine-1
User user1

Host remote_server
User user2
ProxyJump machine-1

and after that, you can simply issue ssh remote_server command to log in to the remote_server, using machine-1 as a stepping stone.