SSH to a Host With Multiple Hops

If you want to make an SSH connection to a host which is reachable only with multiple ssh connections you may use below command to connect it easly. (Note that older versions of ssh do not have this option but you can use some workarounds to do the same (proxy command and etc.))

Assume that you are in A, want to access hostC which is only reachable through hostB

A –> hostB –> hostC

then the command becomes:

ssh -J @hostB @hostC

this will give you a ssh to hostC.

Furthermore, if you are lazy enough to type this long command every time (and you also may jump several times) you can put this command in your ssh configuration. For instance, in your home folder:

vi .ssh/config

And add following as your needs

Host hostC 
    HostName 192.168.1.88
    ProxyJump user1@hostB 
    User root

and you can issue an SSH connection like below:

ssh hostC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s