SSH Escape Sequences: Reviving a Frozen Terminal
SSH session froze, Ctrl+C does nothing, Ctrl+D spits out garbage — familiar situation. Before closing the terminal and losing the session, try built-in escape sequences. They operate at the SSH client level before data reaches the remote host.
How to invoke escape sequences
The default escape character is tilde (~). The combination works only at the beginning of a line. Press Enter, then ~, then the desired symbol. For example, ~. terminates the connection.
If tilde does not work — make sure you pressed Enter before it. In the middle of terminal output the sequence is ignored.
Escape sequence reference
This command prints the list of available escape sequences directly into the terminal.
You do not need to memorize everything. Keep three scenarios in mind — they cover 90% of problems.
Emergency disconnect
~. closes the SSH connection immediately, including all multiplexed sessions. Works even if the remote host is not responding. Do not confuse it with ~^Z (suspend) — that leaves the session alive as a background process.
Forced disconnect does not send SIGHUP to the remote side. If an important process was running without nohup — it will die.
Breaking the data flow
~V (Shift+v) lowers the logging level. The reverse command — ~v — increases verbosity. In practice useful when you see a stream of meaningless debug messages and want to hide them.
A more radical option — ~B. Sends BREAK to the remote system. This can interrupt a stuck process that is listening on a serial port. Use deliberately: not all systems handle BREAK correctly.
Built-in command mode
You enter the SSH client command line. Here you can manage tunnels on the fly without reconnecting.
Command mode is convenient when you forgot to forward a port before connecting. No need to reconnect — add it directly from the session.
Format: -L [bind_addr:]port:host:hostport and -R [bind_addr:]port:host:hostport. Bind address localhost restricts forwarding to the local interface only.
Forced rekey
Forcibly initiates re-keying of the session. Sometimes useful when you notice strange delays or suspect encryption issues. In practice rare, but worth knowing.
Escape sequence summary
| Sequence | Action |
|---|---|
~. | Emergency disconnect |
~V | Decrease verbosity |
~v | Increase verbosity |
~C | Command line (tunnels) |
~R | Forced rekey |
~B | Send BREAK |
~? | Show help |
~^Z | Suspend ssh |
~# | List forwarded connections |
~& | Background mode (on disconnect) |
~~ | Send literal tilde |
Changing the escape character
If you need tilde in the remote session (for example, connecting to Cisco equipment), change the escape character:
Now escape sequences are invoked via ^Z instead of ~. Found in specific scenarios — do not touch without need.
You cannot change the character on the fly in an active session. Only at connection time via the -e flag.
Common pitfalls
~does not work — forgot to press Enter before it.- Session is frozen but you are not sure SSH is still alive — try
~.blind. It will not make things worse. - Multiplexing session (
ssh -M) is bound to the control socket.~.closes all related sessions at once. - If you use PuTTY — escape sequences are different. There
~.sends a literal tilde and dot. UseCtrl+]and thenclose.
When escape sequences will not help
- Network is physically unavailable — only disconnect.
- Remote process consumed stdin — ssh will receive nothing.
- Problem is at the terminal emulator level — killall ssh, then check tmux/screen.
SSH escape sequences are the first-line tool when a session freezes. Keep ~. for disconnect and ~C for tunnels in mind — that is enough for everyday use.