Recently I got a tip about subsequent adding of port forwardings to SSH Sessions without logout/login. As I work a lot with cloud technology and therefore use openssh very frequently, I found this very handy and use it several times a day.

Basically you enter openssh’s escape sequence ~ (only recognized immediately after newline), followed by Shift + C. This should give you a ssh> prompt. After that, you can use the port forwarding command option syntax without the leading dash.

1
user@sshhost $ ~C
ssh> L8080:localhost:8080
Forwarding port.

user@sshhost $

You can also cancel an existing port forwarding.

1
user@sshhost $ ~C
ssh> KL8080
Canceled forwarding.

user@sshhost $

If you are connected through multiple nested SSH connections, you can choose to modify the next deeper nested connection by adding one more ~ escape character.

There are additional useful escape sequences (for example to terminate hanging connections by ~.).

1
user@sshhost $ ~?
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
 ~V/v - decrease/increase verbosity (LogLevel)
 ~^Z  - suspend ssh
 ~#   - list forwarded connections
 ~&   - background ssh (when waiting for connections to terminate)
 ~?   - this message
 ~~   - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

Cheers,
visit