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.

  • 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 ~?.

| improve this answer | |
  • 1
    That seems perfect. I'll let you know when I get a chance to test it ;-) – Stefano Palazzo Jul 16 '11 at 14:12
  • 1
    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
  • 2
    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+`.

| improve this answer | |
  • 1
    Nope, doesn't work. – Cerin Feb 29 '16 at 2:35
  • 2
    Amazing! It works! – Yekver Dec 15 '16 at 7:38
  • Kudos for pointing how to get the tilde. – cerebrou May 22 '19 at 10:05
  • Clearer than the accepted answer. Thanks! – Jee Feb 2 at 5:32

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