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.

  • Awesome! Glad I could help.
    – James T
    Jun 3 '10 at 3:47

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.

  • [enter]~. works like a charm! Thank you! I can't believe I only now learned this trick. This has been an annoyance for, literally, years. Interestingly, it only works when the connection has died and the terminal is frozen. If it can tell the difference why can't it just do this automatically when the connection dies?
    – dreeves
    Jun 2 '10 at 23:26
  • Thats strange that it only works when your connection died. What gets me all the time is forgetting to press enter first. If you start to type something and backspace to the beginning again... then ~. won't work. I expect there are ways to change the connection timeout. I expect the long timeout was written in so that connection delays between old modems would not drop the session all the time. I added some more stuff to the solution that you might find interesting.
    – James T
    Jun 3 '10 at 0:05
  • I was wrong! It does work regardless of whether the connection has died. Thanks again, James. I owe you big time.
    – dreeves
    Jun 3 '10 at 3:29
  • How do I install ssc on Ubuntu? apt-get shows nothing, and ssc is such a generic set of initials that my Googling yields nothing relevant. Aug 21 '14 at 17:26
  • Ooops, I posted this comment in the wrong page. I was supposed to post it here: stackoverflow.com/questions/474967/… , but even that I misread. ssc is what an individual created, it's not a well known tool that I thought it was. Aug 23 '14 at 3:15

Something is holding the connection open, probably from some sort of forwarding. You can try to use Ctrl\ to force ssh to die, but in general you should try to figure out what is wedging it open.

  • Ctrl-\ isn't mapped to SIGQUIT on the Mac.
    – Spiff
    Jun 2 '10 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.