If your first SSH server (my.server.com
) supports TCP Port Forwarding, you can forward a port on your local system (localhost
) to my.server2.com
via my.server.com
:
ssh -fNL 2022:my.server2.com:22 [email protected]
This will forward port 2022 on localhost
to port 22 on my.server2.com
. Then you can connect directly to the second server:
ssh myUser2@localhost:2022
In Nautilus, you can connect using ssh://myUser2@localhost:2022
.
The -fN
flags send SSH to the background, and creates a problem in closing it. There are three ways out:
Autoclose
ssh -fNL 2022:my.server2.com:22 [email protected] sleep 10
Now connect using Nautilus before the sleep command finishes executing (10 seconds). The connection will be kept alive as long as Nautilus is connected. When done, disconnect from Nautilus and the connection will be stopped.
Let the command wait for input
ssh -tL 2022:my.server2.com:22 [email protected] 'read -p"Press Enter to exit: "'
The read
command will wait for input. Press Enter when you're done to close the connection.
Look up the connection process and kill it
pgrep -fa fNL
This will show you all processes which have fNL
in the command line (there should only be your SSH connection process).
Either kill
the PID of the right process if there are more than one, or use pkill
if there is only one process:
pkill -f fNL
This is pretty much the only option for connections that have already been established using -fN
.
Run no command, and exit as usual
ssh -L 2022:my.server2.com:22 [email protected]
This will open a normal shell, from which you can exit as you normally do.