This question already has an answer here:

When my SSH session times out, the whole terminal freezes.

Is there any way to break out of that connection? CTRL+C doesn't cut it.

marked as duplicate by phunehehe, Anthon, slm, Gilles, Mat Jun 5 '13 at 13:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What about Alt + SysReq + O? (Please note that I am only kidding!) – Nathan Osman Jun 5 '13 at 5:36

You need to send the ssh escape sequence, which by default is ~ at the beginning of a line (in other words, preceded by a newline, or enter). Then send the disconnect character, which is ..


host1> ssh host2
Last login: Tue Jun  4 21:56:26 2013 from host1

(host2 freezes, press enter~.)

host2> Connection to host2 closed.

See the ssh(1) manual:

-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.

  • 1
    This answer is amazing – casey May 3 '18 at 19:25

You could kill the ssh process - ie, from another terminal using kill or killall.

... But Bahamat's way is the better, cleaner way.

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