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.
Also read: Bash Keyboard Shortcuts for the pro!
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]
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.
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
A man with a tech effusive who has explored some of the amazing technology stuff and is exploring more. While moving towards, I had a chance to work on Android development, Linux, AWS, and DevOps with several open-source tools.