Saturday 2 August 2014

Force logout a user in Linux or Unix

There can be several users logged in Linux/Unix system and they all have different sessions.
[root@linux]# w
10:23:27 up 4:40, 4 users, load average: 1.44, 1.29, 1.27
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 xxx.xx.xxx.xx 05:44 3:04m 0.12s 0.12s -bash
root pts/2 xxx.xx.xxx.xx 05:46 4:37m 0.06s 0.06s -bash
root pts/3 xxx.xx.xxx.xx 05:46 4:37m 0.06s 0.06s -bash
root pts/4 xxx.xx.xxx.xx 06:49 0.00s 0.27s 0.00s w
[root@linux]#
(Where xxx.xx.xxx.xx is the IP from where connections are made.

You can find the process of the session by following command:
ps -dN|grep pts/3 (Where pts3 is seesion no.)
after entering the above command following output will come:
15552 pts/3 00:00:00 bash
Then you can kill the process by:
kill -9 15552
That session will be terminated. Hope it helps !

Force logout a user in Linux or Unix