Ever had a SSH session hang when you loose network connection, or when the remote machine hangs? Then couldn’t escape from SSH?

I always resorted to closing the window or killing the process. But now with two key strokes the trouble’s gone! Pressing “~” drops you into SSH’s secret set of internal commands. You can retrieve a full list of command by running “~?“.

Now by just typing “~.” I can kill any hanging ssh connection. Useful! (One tip: issue he keystrokes quickly, ssh seems to ignore you if you type too slowly).

[user@host ~]# ~?
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.)