SSH Jumphosts

From UMIACS
Jump to navigation Jump to search

Sometimes it is necessary to SSH through a host in order to access another host. Although this can be done by manually SSH-ing from one host to another repeatedly, the same task can be accomplished in one line by jumphosting.

Dynamic Jumphosts

Dynamic jumphosts are most useful for times in which you only need to make this jump once, or rather infrequently.

The basic format for jumphosting is

 ssh -J user1@host1:port1 user2@host2:port2

However, if ports are the same for different hosts, you can use the format

 ssh -J user1@host1 user2@host2

Also, if you need to jumphost through multiple hosts, the format below is also legal

 ssh -J user1@host1:port1,user2@host2:port2 user3@host3

Static Jumphosts

Static jumphosts are most useful for times in which you will often need to make this jump, and allows you type a short, simple command instead of the longer line as shown in Dynamic Jumphosts section above. In order to create this shortcut, you must edit your ~/.ssh/config file.

Setup

In your ~/.ssh/config file

  Host directJump
     HostName mydirectjump.example.org
  
  Host secondJump
     HostName mysecondjump.example.org
     ProxyJump directJump

If another jump is needed, the following format can be added as needed to the same ~/.ssh/config file

  Host finalJump
     HostName myfinaljump.example.org
     ProxyJump secondJump

Use

After saving the above changes to your ~/.ssh/config file, if you wish to access that final host

  ssh finalJump