Skip to content
Home » Linux » How to Kill Online Users on Linux

How to Kill Online Users on Linux

At times, there're some unconnected sessions on the server, which were interrupted by accident on the client side, and you might want to remove them to keep the server clean.

Let's see my case for an instance, first of all, list all the online users now.
[root@localhost ~]# w
 22:17:51 up 98 days, 18:19,  2 users,  load average: 0.00, 0.05, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/1    192.168.10.123   22:02    0.00s  0.05s  0.00s w
steven   tty5     -                22:17    4.00s  0.00s  0.00s -bash

There's a user steven which console was terminated abnormally and it's no longer used. We were trying to remove the unused session from the system.

Let's see what processes relate to steven.
[root@localhost ~]# ps -ef | grep steven
root     20930     1  0 22:16 ?        00:00:00 login -- steven
steven   20934 20930  0 22:17 tty5     00:00:00 -bash
...

Found a root process named login -- steven which initiated the session. So let's kill the root process 20930 on the first line.
[root@localhost ~]# kill -9 20930
The user steven was gone.
[root@localhost ~]# w
 22:18:57 up 51 days, 18:20,  1 user,  load average: 0.00, 0.03, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/1    192.168.10.123   22:02    0.00s  0.05s  0.00s w
[root@localhost ~]# ps -ef | grep steven
...

Leave a Reply

Your email address will not be published. Required fields are marked *