SSH Escape Sequence
I was pleasantly surprised to learn that OpenSSH has a number of very useful commands available via an escape sequence (the default escape key is ~
preceded by a newline, and can be configured with the EscapeChar
directive in your ssh_config
). The ~?
sequence presents a list of available commands:
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
(Note that escapes are only recognized immediately after newline.) The ~.
sequence is worth committing to memory for those (frequent, for me) situations where you wind up with an unresponsive ssh session. The ~C
option is also handy, in that allows the opening/closing of forwarded ports on-the-fly:
Commands:
-L[bind_address:]port:host:hostport Request local forward
-R[bind_address:]port:host:hostport Request remote forward
-D[bind_address:]port Request dynamic forward
-KR[bind_address:]port Cancel remote forward
Very useful to know if you use ssh frequently.