You can use the ProxyJump
option in ~/.ssh/config
. From man ssh
:
-J destination
Connect to the target host by first making a ssh connection to the jump host described by destination and then
establishing a TCP forwarding to the ultimate destination from there.
Multiple jump hops may be specified separated by comma characters.
This is a shortcut to specify a ProxyJump configuration directive.
Note that configuration directives supplied on the command-line
generally apply to the destination host and not any specified jump
hosts. Use ~/.ssh/config to specify configuration for jump hosts.
For example, your ~/.ssh/config
may look like this:
Host serverA
Port 22
Host serverB
Port 22
ProxyJump serverA
This will tell ssh
to always connect to serverB via serverA, and it will do this for both normal ssh
and for scp
. In other words, you can type ssh serverB
or scp serverB:big_file.txt .
and it will know to route through ServerA. (You will, however, need a local copy of the key needed for serverB if you are using public key authentication.)
This is often referred to has "jump host" in ssh
. A related config option in ~/.ssh/config
is ProxyCommand
.