Linux – ssh sessions in xterms freeze for many minutes whenever they disconnect

cygwin;linuxmacossshterminal

If I ssh to a remote machine and then lose internet connectivity, the session freezes.
I can't control-c or otherwise abort and go back to my local xterm or terminal prompt but if I wait several minutes it will do so.
There must be some way to force it to abort the remote ssh session when connectivity is lost.
I'm on a Mac but I believe this happens on cygwin or linux as well.

Best Answer

Tilda period should do what you want (~.). It must be the first thing typed after pressing enter, so press enter and then type it. Here is the manual entry for ssh:

 -e escape_char
         Sets the escape character for sessions with a pty (default: ‘~’).
         The escape character is only recognized at the beginning of a
         line.  The escape character followed by a dot (‘.’) closes the
         connection; followed by control-Z suspends the connection; and
         followed by itself sends the escape character once.  Setting the
         character to “none” disables any escapes and makes the session
         fully transparent.

ctrl-d might also work.

Edit: SSH has a lot of escape character commands built in. With an active SSH session open you can press [enter]~? to see a list of options. This is all in the man entry for ssh. If you don't already know about man entries... you will discover a world of amazingness! In the linux terminal type "man command" in this case "man ssh" without the quotes. It has lots of information. Press "q" to quit. You can also type "info ssh" if you like the info interface better.

Related Question