This question already has an answer here:

From time to time, SSH sessions to my servers just freeze up and then neither Ctrl+C nor Ctrl+\ do anything.

How do I quit the session without just closing the Terminal it's in?


The session is locked as in, no keys are transmitted to the server. I'd like to shut it down gracefully, such that the user isn't logged in anymore.

I know I can kill the SSH client, but that will, in time, make the "2 users" info message I get from uptime meaningless. I'd like to know how many users are really logged in.

marked as duplicate by Eric Carvalho, waltinator, BuZZ-dEE, g_p, Fabby Jan 14 '15 at 8:28

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.

  • 2
    If you force quit your ssh session, the bash process on the remote server should be killed, causing you to log out. None of my servers keep me logged in after the SSH connections freeze (I'm using the default settings). – Andrew Gunnerson Jul 14 '11 at 23:18

To disconnect a locked-up ssh session, typeEnter ~.

A full list of escape codes can be found in the ssh manpage or by typing ~?.

  • That seems perfect. I'll let you know when I get a chance to test it ;-) – Stefano Palazzo Jul 16 '11 at 14:12
  • It's very hard to type on the German keyboard, where the ~ is a dead key. But when I get it right, it works perfectly. – Stefano Palazzo Aug 5 '11 at 9:29
  • 13
    I needed the preceding Enter from @Jacob's answer – jpillora Oct 24 '14 at 8:35
  • This does not work... – Cerin Feb 29 '16 at 2:34
  • On the German keyboard, <kbd>option+n+.<kbd> will print <kbd>~<kbd> and immediately <kbd>.<kbd> again. – BTR Naidu Jun 27 '16 at 10:24

Type the following key sequence: Enter, ~, .. On US keyboards, the tilde (~) is Shift+`.

  • Nope, doesn't work. – Cerin Feb 29 '16 at 2:35
  • 1
    Amazing! It works! – Yekver Dec 15 '16 at 7:38

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