How to kill a dead SSH session gracefully

I have a bad habit of leaving an open SSH session sitting there and then coming back to it to realize that it’s dead. In the past, I’ve just killed the terminal to end it. Here’s a better way:

<Enter>~.

That’s the enter key followed by the tilda character followed by a period.

To explain, SSH has a few different escape sequences. To see them, run ~? while in an open SSH session. Here they are:

mcrittenden@freshbox$ ~?
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.)

As you can see, ~. is the escape sequence to terminate the connection, and the note at the end says that they’re only recognized immediately following a newline, hence <Enter>~.