Pkill

From DikapediaV2
Revision as of 18:31, 17 October 2024 by Ardika Sulistija (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

pkill – Kill user session and forcefully logout of the system.

Ref: https://www.cyberciti.biz/faq/linux-command-log-off-all-existing-sessions-accounts/#:~:text=a%5D%20who%20or%20w%20command%20%E2%80%93%20Show%20who,to%20be%20brought%20down%20in%20a%20safe%20way.

Use the who command to see list of logged in users as follows:

# w

OR

# who

Sample outputs:

root     pts/0        Jul 29 13:53 (10.1.6.120)
nixcraft pts/1        Jul 29 12:30 (10.1.6.121)
sailee   pts/2        Jul 29 12:33 (10.1.6.121)

To force and logout nixcraft and sailee user, enter:

# pkill -KILL -u nixcraft
# pkill -KILL -u sailee

Alternatively, just try bash and friends kung-fu and save time:

### warning must be run as root or via sudo ###
who | awk '!/root/{ cmd="/sbin/pkill -KILL -u " $1; system(cmd)}'

OR

### warning must be run as root or via sudo ###
### Safe version :) ###
who | awk '$1 !~ /root/{ cmd="/sbin/pkill -KILL -u " $1; system(cmd)}'