If you have an unresponsive or hung SSH session on a Linux or UNIX system, you can try to kill the session by using the kill
command. This will terminate the process associated with the session and close the connection.
To do this, you will need to find the process ID (PID) of the SSH session. You can do this by using the ps
command with the aux
options, which will show all processes on the system and their associated PIDs.
For example:
ps aux | grep sshSource:www.lautturi.com
This will show output similar to the following:
user1 1234 0.0 0.1 1234 1234 pts/0 00:00:00 ssh user@example.com user2 5678 0.0 0.1 5678 5678 pts/1 00:00:00 ssh user@example.com
In this example, the PIDs for the two SSH sessions are 1234 and 5678.
To kill one of these sessions, you can use the kill
command followed by the PID of the session. For example:
kill 1234
This will send a signal to the process with PID 1234, which will terminate it and close the connection.
If the kill
command does not work, you can try using the kill -9
command, which sends a stronger signal that can force the process to terminate. For example:
kill -9 1234
Keep in mind that killing a process can cause data loss or corruption, so it should be used as a last resort when other methods have failed.