Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

SSH Escape Sequences

July 21, 2023 — Gregg Szumowski

Have you ever had an SSH connection timeout on you and you’re left with what looks like a locked session. Repeatedly hitting the Enter key does nothing. It seems that there is nothing that you can do except close the console terminal session…or is there something else?

Many people are not aware that SSH has its own set of keyboard shortcuts. The solution to the above problem is to terminate the connection using the first of these shortcuts.

  1. Press the Enter key.
  2. Press the tilde followed by a period.
  3. Press Enter again. You should now be back at your command prompt.

Supported escape sequences:
~. - terminate connection (and any multiplexed sessions)
~B - send a BREAK to the remote system
~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.)

It is important to note that you always press the Enter key before typing the key sequences above.

Tags: cli, ssh, shortcuts, motd