Terminate a hanging SSH session

Posted by Marcus Folkesson on Tuesday, June 27, 2017

Terminate a hanging SSH session

It may be very frustrating when SSH sessions just hangs because the target is power cycling or something. Lucky for you there is a "secret" escape sequence that allows you to terminate the session (and a few other things).

The escape sequence is <enter>~X where X is a command letter. To see all available key sequences, type <enter>~?.

Example output:

 1    marcus@Ilos:~$ ~?
 2    Supported escape sequences:
 3      ~.  - terminate connection (and any multiplexed sessions)
 4      ~B  - send a BREAK to the remote system
 5      ~C  - open a command line
 6      ~R  - Request rekey (SSH protocol 2 only)
 7      ~^Z - suspend ssh
 8      ~#  - list forwarded connections
 9      ~&  - background ssh (when waiting for connections to terminate)
10      ~?  - this message
11      ~~  - send the escape character by typing it twice
12    (Note that escapes are only recognized immediately after newline.)

<enter>~. is my favorit. It terminates the connection and keep your mood cheerful.