Sunday, November 13, 2011
2:15 PM

Kicking out a logged in user in Linux

Another thing that I never did before. Suppose, you have a system and there are currently logged in users that you want to terminate. The easiest way to check for logged in users is:

[root@busy-bee log]# w
 13:06:51 up  1:24,  2 users,  load average: 1.15, 1.10, 1.15
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
sarmed   pts/0    192.168.1.6      12:36    0.00s  0.06s  0.03s sshd: sarmed
mujahid  pts/1    192.168.2.9      11:48    1:17m  1:03m  0.04s sshd: mujahid


Now,suppose, I want to terminate the session for user mujahid. This is how it is done-

[root@busy-bee log]# pkill -KILL -u mujahid
[root@busy-bee log]# w
 13:08:47 up  1:26,  1 user,  load average: 1.09, 1.10, 1.14
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
sarmed   pts/0    192.168.1.6      12:36    0.00s  0.08s  0.03s sshd: sarmed

Piece of cake.

Additional options:
To 'pause' a user:
[root@busy-bee log]# pkill -STOP -u mujahid

To 'resume' a user:
[root@busy-bee log]# pkill -CONT -u mujahid

0 comments:

Post a Comment