Close stuck SSH sessions

Something I’ve been looking for as long as I’ve been using SSH is a way to force the SSH client to exit. When dealing with unreliable connections or working with embedded Linux devices, you can often end up with a SSH client that thinks it’s still logged in, and which insists on sending all keystrokes blindly into the aether until the connection finally times out.

There is a way out that doesn’t require opening another terminal to kill the SSH client: press enter, tilde (~), and then period (.), typing each as a separate keystroke. This doesn’t appear to be a well-known feature (perhaps it’s just my poor luck in looking for it), but can be quite a time saver.


  1. Gevious says:

    Thats brilliant. I’ve often wondered how to break out of a dead ssh session. What an obscure way to do it. Thanks for the answer

  2. lfz says:

    What the math??!! It really does work, I wonder what’s the reasoning behind this choice of method to close the stuck sessions.

  3. Gonzalo Cao says:

    That was incredibly cool! So usefull! Looking how to close an ssh connection from another one I’ve find this simple-but-effective method.

    Thanks a lot!

  4. Adam says:

    Thanks a ton. I SSHed into a Sonicwall router that I didn’t have credentials for and it wouldn’t let me out of the infinite loop of Login: Password: prompts, even with ctrl+c. This method worked by typing ~. into the login.

  5. Aaron says:

    Awesome! Not knowing how to get out of a dead session was starting to get on my nerves. Now let’s see if I can remember this cryptic sequence of keys :)

  6. Anish Sane says:

    I often get into a situation, when the ssh target system has crashed/panicked. & I had to use the dirty `kill ssh_pid` method to terminate the process. Thanks a lot for this info.

Leave a Reply

Your email address will not be published. Required fields are marked *