I just recently learned that ssh has an option, ProxyCommand, that allows you to specify a machine (machine B) to be used as a stepping stone when connecting to another machine (machine C). So if you normally establish a connection from your machine (machine A) to B and then establish another connection from B to C, this could save you some time and hassle. Here’s how to do it:
1) Add the following to your ~/.ssh/config:
Host C_hostname
ServerAliveInterval 60
User C_username
ProxyCommand ssh B_username@B_hostname netcat -w 180 %h %p
-Line 1: Specifies the ultimate host we are connecting to (C)
-Line 2: How often, in seconds, ssh will send a keepalive request to C.
-Line 3: Specifies the username to be used when logging in to the ultimate host (C).
-Line 4: Specifies B as the stepping stone to connect to and netcat as the command to run on the stepping stone once connected in order to make the ssh port on C available to your local machine (A). Note, on some machines netcat is named nc. The -w option specifies the timeout in seconds for netcat. `%h’ will be substituted with the hostname specified in line 1 (C_hostname) and `%p’ with the default ssh port (22).