Notes
SSH Tunneling / Port Forwarding
local port forwarding with ssh -L through a jump host, what -f, -N and -L actually do, and how to close the tunnel
Linux
1ssh -f -N -L 2222:vortex.myserver.com:22 user@jumphost
-fgo to the background (just before running the command, so you can still type a password first). It does NOT mean force-Llocal port forward, in the formlocal_port:destination_host:destination_port-Ndon’t execute any commands at remote host, just forward the port2222is local portvortex.myserver.comis remote server, the one you actually want to reach22is remote portuser@jumphostis the server you SSH into. The connection tovortex.myserver.com:22is made from there, sovortexonly has to be reachable from the jump host, not from youssh -L 2222:vortex.myserver.com:22 localhostonly works if you run an SSH server on your own machine, because thenlocalhostis the server you log into
Now connect to the local port, and you end up on vortex:
1ssh -p 2222 user@localhost
It looks like you have connected to yourself, but what you have done is you’ve tunneled your connection on the 2222 local port. Now you have a gateway to a remote network.
To close the tunnel, find the background ssh process and kill it
1pgrep -af 'ssh -f -N -L 2222'
2kill <pid>
Links
- man ssh:
-f,-L,-N