94

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?


Clarification:

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.

1
  • 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). Jul 14, 2011 at 23:18

2 Answers 2

141

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

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

8
  • 1
    That seems perfect. I'll let you know when I get a chance to test it ;-) Jul 16, 2011 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. Aug 5, 2011 at 9:29
  • 14
    I needed the preceding Enter from @Jacob's answer
    – jpillora
    Oct 24, 2014 at 8:35
  • 2
    This does not work...
    – Cerin
    Feb 29, 2016 at 2:34
  • 1
    In brazil you must press SPACE beetween ~ and .
    – 777Anon
    Nov 22, 2017 at 16:50
64

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

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

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