Kill pts session Linux Users

Thanks to http://tasos.pavta.com

Let’s assume that you are connected to a server via ssh and for some reason you get disconnected. Then most probably you will be left with an idle user session on the server.

The w command can tell you in linux about who is connected to the server. And you can easily see here in the idle collumn that there is one idle session from the user ‘tasos’.

root@srv1 [~]# w
11:55:34 up 5 days, 15:12,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
tasos pts/0    77.49.225.63.dsl 11:08    29:23 0.01s  0.09s sshd: tasos
tasos pts/1    193.92.244.63.ds 11:40    0.00s   0.03s  0.07s sshd: tasos

There are many ways to kill such a session. Below i will show you one of them.
First run pstree -p and try to find something like this…

sshd(32560)─┬─sshd(28407)───sshd(28416)───bash(28419)
……………………└─sshd(29700)───sshd(29708)───bash(29711)───pstree(29844)

After the pstree -p command we have to find the parrent pid for the dead session (ssh in our example) . So after we find something like the example above we have to kill -1 the parent pid.

In our example you can see that there is one common process, sshd(32560) with two branches for the two users being connected (1 is me, the current user and the other is the user with the dead session which happens to be me again).

The solution is to kill the branch with the dead user…In our example this would be sshd(28407)….so simply do a kill-1 28407 and then with the w command you can see that there is only one user connectd…you!

OR

skill -KILL -v pts/0

OR

$ ps -ft pts/2
11236

$ kill -9 11236
Advertisements
Posted in Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: