Skip to content

Instantly share code, notes, and snippets.

@dwallraff
Last active March 16, 2025 10:40
Show Gist options
  • Save dwallraff/685a6b14a6f597c46e683297fc54b284 to your computer and use it in GitHub Desktop.
Save dwallraff/685a6b14a6f597c46e683297fc54b284 to your computer and use it in GitHub Desktop.
Add port forwarding to running SSH sessions

Use SSH's escape sequence <enter>~<shift>+c

user@sshhost $ ~C
ssh> L8080:localhost:8080
Forwarding port.
user@sshhost $ ~C
ssh> KL8080
Canceled forwarding.

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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment