Mac – SSH through jump sever using private key (in macbook)

macsshssh-tunnel

I am trying to do SSH where target server is accessible through jump server only.

 +-------+       +----------+      +--------------+
 | Laptop| <---> | Jumphost | <--> | TargetServer |
 +-------+       +----------+      +--------------+

To access the server, I have to use my private key.

I recently shifted to MAC from Windows machine.
In windows I was using WINSCP tool and through tunnel option in WINSCP and Allowing agent forwarding I was able to access the target servers.

Target server setting:
enter image description here

Tunnel setting:
enter image description here

Authentication/Agent forwarding setting
enter image description here

I have placed same private key in both the settings.

Now I am looking for direct SSH command (to execute on MAC) so that I can access servers.

I have tried the following command

ssh -i privatekey.pem -Ao ProxyCommand="ssh -i privatekey.pem user@jumpserver" user@targethostname

but getting an error:

-bash: line 1: $'SSH-2.0-OpenSSH_7.6\r': command not found

Best Answer

Following command worked for me

ssh -i privatekey.pem -o "ProxyCommand ssh -W %h:%p -i privatekey.pem user@jumpserverhost" user@targetserver
Related Question