My answer is really the same as all the other answers here, but, I wanted to clarify the usefulness of ~/.ssh/config
and ProxyJump.
Let say I need to get to a destination in 3 hops, and, for each hop, I needed a specific username, host, port and identity. Because of the identity criteria, this can only be done with the ~/.ssh/config
config file:
Host hop1
User user1
HostName host1
Port 22
IdentityFile ~/.ssh/pem/identity1.pem
Host hop2
User user2
HostName host2
Port 22
IdentityFile ~/.ssh/pem/identity2.pem
ProxyJump hop1
Host hop3
User user3
HostName host3
Port 22
IdentityFile ~/.ssh/pem/identity3.pem
ProxyJump hop2
From your computer, you can test each jump individually, i.e.
$ ssh hop1 # will go from your PC to the host1 in a single step
$ ssh hop2 # will go from your PC to host1, then from host1 to host2, i.e. in two steps
$ ssh hop3 # will go from your PC to host1, then to host2, then to host3, i.e. in three steps
Another cool thing about the ~/.ssh/config
file is that this will also enable sftp
file transfers, e.g.
$ sftp hop1 # will connect your PC to host1 (i.e. file transfer between your PC and host1)
$ sftp hop2 # will connect your PC to host1 to host2 (i.e. file transfer between your PC and host2)
$ sftp hop3 # will connect your PC to host1 to host2 to host3 (i.e. file transfer between your PC and host3)
@prongs Have you managed to use this for SOCKS proxy (all those years ago)? – Drux – 2017-12-08T07:32:16.857
2What did you use it for? I want to use it for socks proxy. Will it work? – prongs – 2012-02-29T13:57:54.117
2Yes, you should be able to use the tunneled connection as a SOCKS proxy, unless
host2
denies forwarding – Mala – 2012-05-03T06:48:05.493I was thinking about creating a wrapper over SSH that would set up that using multiple use of ProxyCommand. – Pavel Šimerda – 2013-10-19T20:52:18.257