Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Log Everyone Out Of The System  (Read 4894 times)

0 Members and 1 Guest are viewing this topic.

rohitj

  • Guest
Log Everyone Out Of The System
« on: October 26, 2013, 02:38:55 pm »
Log Everyone Out Of The System


If you want to log out all other users in a system, you can use pkill command.

who or w command - Show who is logged on and what they are doing.

pkill command - Kill user session and forcefully logout of the system.

For Example :

==========
root@vps [~]# w
root     pts/0    * 00:17    4:43m  0.04s  0.04s -bash
test     pts/4    *  05:04    3.00s  0.00s  0.00s -bash

root@vps [~]# pkill -KILL -u test
root@vps [~]# w
root     pts/0    * 00:17    4:45m  0.06s  0.06s -bash
==========

OR you can run below script.

who | awk '!/root/{ cmd="/sbin/pkill -KILL -u " $1; system(cmd)}'

Note : You have to run above script as root