How to Kill an Unresponsive SSH Connection in Linux

While working with a remote connection, it’s quite common to get into a situation where you are not able to interact with the remote system.

And it is a frustrating moment when a remote SSH connection hangs after several minutes of unused connection, or perhaps even due to internet fluctuations.

There might be many other reasons for the above cause, but it’s quite easy to kill an unresponsive SSH connection without killing the current shell.

How to Kill an Unresponsive SSH Connection

You can kill an unresponsive SSH connection in various ways, like killing a process from another terminal or forcefully killing the current shell, but I don’t do it anymore because I know the secret keybinding or command that can drop the unresponsive SSH connection.

I believe you are in a hurry to know the keybinding to get out of the frozen terminal, so let me show you how you can perform the following steps. Later, I will explain to you how you can prevent the above scenario.

  • Step 1. Go to the terminal where the SSH connection is running, and press Enter
  • Step 2. Now use the tilde key "~". If you are using the standard 105 key, then you have to press Shift + ~ keybinding to activate the tilde "",and some keyboards require you to press the grave key button twice to activate the tilde.
  • Step 3. Lastly, press ".", which will close the connection.

Once you invoke the above keybinding, you will be back at your host terminal.

For your better understanding, let me try this one on my local system, so I have started the virtual machine, and let me connect to my “machine_1” using an SSH connection.

$ ssh [email protected]
Login to machine_1 using ssh
Login to machine_1 using ssh

Now I’m connected to “machine_1“.

The next step is to disconnect the network connection to my virtual machine. If you are thinking about why I have disconnected the connection, then the reason is pretty simple: it will break the connection between host and server, which is also one of the reasons behind the unresponsive terminal.

You can follow the below steps to disconnect the network connection from the virtual machine.

Once I am done with the above step, my host side terminal will get frozen or unresponsive and, hence I will not be able to communicate with my “machine_1” anymore.

As we discussed, to get out of an unresponsive terminal, I have to enter the following sequence of keys on the unresponsive terminal: "Enter" + "~" + "."

That’s all it takes to come out of an unresponsive terminal.

Wrap up

From the above, you learned how to come out of the unresponsive terminal.

Situations like a network down or any other circumstance are unavoidable. Still, you can prevent your SSH connection from getting disconnected by following the next article: How to Keep SSH Terminal Sessions Alive in Linux

This Post Has One Comment

  1. Jasper Brannigan

    If you are having problems with SSH connection, maybe it is time to consider using MOSH (MObile SHell) + TMUX (which is still secure since the connection is still over SSH) which when properly setup up allows one to reconnect to the remote session as if no break had occurred because the remote session is still running in TMUX (unless the remote machine has been rebooted). See the website at mosh dot org.

Leave a Reply