SSH: On the fly port forwarding.

[Post Updated]

Once inside an SSH session, you may realize that you need to reach another box via the local port redirect (-L 1234:192.168.0.5:23 for example).

Most people think you need to kill your SSH session to add a new -L option, then reinitiate the SSH session; this is NOT true.

You can open an internal SSH shell within an SSH session to add new redirects!

From within an SSH session, simply type (the ~ is the tilde character, which is shift + the key to the left of the number 1)

~# then hit

~C then hit (capital C)

Then type: help and <enter>

You’ll see a listing of available commands. To add a new local redirect, just type

-L 4567:192.168.0.12:5900, then hit <enter>

…and voilà, you’ve added a new local redirect. Just hit <enter> once, and you’ll be dropped back into command line.

There are other escape-commands. Just type ~? from within an SSH session for more escape-commands.

Just press <enter> on a line by itself to return back to the SSH session.

FYI: This also works for remote redirects, as well.

Here’s a Google search link offering more info:

Leave a Reply