Last Updated: August 19, 2016
·
16.71K
· bjeanes

Start port forwarding over an *existing* SSH connection instead of creating a new one

This tip is for when you have an existing SSH session running but forgot to start port forwarding over the connection. Typically, people would close the connection and create a new one. However there is an alternative.

On your existing connection, simply type <enter>~C to bring up a console with your local SSH client (not the server). The provided console accepts a few of the ssh commands options, including -R, -L.

So, for example, if I wanted to suddenly access some service running on port 4321 on my local machine from the server, I could type <enter>~C-R 1234:localhost:4321<enter> and I would immediately have access to that resource from the server on localhost:4321 (that's the server's localhost).

~ (tilde) is the SSH's default EscapeChar. You press <enter> first to clear the buffer, the ~ escape char and any one of a number of options.

For example, the full list of options that the client of my version of OpenSSH supports is (gotten with <enter>~?):

Supported escape sequences:
  ~.  - terminate connection (and any multiplexed sessions)
  ~B  - send a BREAK to the remote system
  ~C  - open a command line
  ~R  - Request rekey (SSH protocol 2 only)
  ~^Z - suspend ssh
  ~#  - list forwarded connections
  ~&  - background ssh (when waiting for connections to terminate)
  ~?  - this message
  ~~  - send the escape character by typing it twice

1 Response
Add your response

Thanks a lot! Didn't know that!

over 1 year ago ·