Usually when I connect to a remote server via SSH, I am very fond of opening 2 or more connections to that server on several terminal windows. Often I close the terminal window before doing a proper `logout` from the SSH session. In most cases, the SSH connection should disconnect and the corresponding process will no longer be there. But in other instances that process will continue to run on the remote server. This has happened to me several times.
There are 2 ways that I have found out to force disconnect (or Kill) the unused SSH sessions on the remote server.
Before anything else, know where you’re at so that you will not end up disconnecting your current active session. Use `tty` command to know on which tty you are working on. The command will give you something like /dev/pts/0.
Next is to know which are sessions by listing it down using the `who` command. Or simple press “w” to get a list like the one below.
(1) The first is with a 2-step approach. Use the following `ps` command to get the process Id of the said session. Then you can use `kill` to terminate the process.
ps -dN | grep pts/0
The result will be similar to this:
3948 pts/0 00:00:00 bash
Terminate the process with:
kill -9 3948
(2) The second way is a more direct approach using `pkill`.
pkill -9 -t pts/0
The above will immediately kill the said process that is associated to pts/0.
If you want to play it safe, I suggest you use #1.
- > When Remmina Can No Longer Connect To Remote Server October 2, 2013
- > How To Set Default Desktop Session On Ubuntu June 11, 2011
- > SUSE Kickoff Menu October 31, 2006
- > “Could not open a connection to your authentication agent” SSH-Add Error December 4, 2012
- > Fix ./gradlew Permission Denied On OpenShift Deploy August 15, 2020