How to tunnel intermediate server(s) to connect the end server with ssh.
- Caution!
- If you use windows, use C:\Windows\System32\OpenSSH\ssh.exe instead of ssh for ProxyCommand section.
Create a public-private key pair on your working machine (e.g. laptop).
$ ssh-kengen
Add your public key into the .ssh/authorized_keys file in all intermediate and end servers. Be carefult that .ssh (700) and .ssh/authorized_keys (644) have proper permissions.
Add the following configuration in your working machine's .ssh/config file.
Host intermediate_server_01
HostName intermediate_server_01.xyz.com
User myuser
Host intermediate_server_02
HostName intermediate_server_02.xyz.com
User myuser
StrictHostKeyChecking no
ProxyCommand ssh -W %h:%p intermediate_server_01
Host end_server
HostName end_server.xyz.com
User myuser
StrictHostKeyChecking no
ProxyCommand ssh -W %h:%p intermediate_server_02