Can login as root user on Debian or Ubuntu/RHEL/CentOS Linux based system. I need to log everyone off (all ssh users) to install new kernel and/or hardware. How do I do this on Linux? What is the best way to logout ALL USERS remotely over the ssh based session in Linux like operating systems?
Can login as root user on Debian or Ubuntu/RHEL/CentOS Linux based
system. I need to log everyone off (all ssh users) to install new kernel
and/or hardware. How do I do this on Linux? What is the best way to
logout ALL USERS remotely over the ssh based session in Linux like
operating systems?
You need to use the following commands:
a] who or w command – Show who is logged on and what they are doing.
b] pkill command – Kill user session and forcefully logout of the system.
c] shutdown command – Arranges for the system to be brought down in a safe way.
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) tola pts/1 Jul 29 12:30 (10.1.6.121) tender pts/2 Jul 29 12:33 (10.1.6.121)
To force and logout nixcraft and sailee user, enter:
# pkill -KILL -u tola
# pkill -KILL -u tender
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)}' |
Finally, you can shutdown the system as follows:
# shutdown -h now
Instead of killing all users one by one you can type the following shutdown command with the warning message:
# shutdown -h +10 "Server is going down for maintenance in 10 minute. Please save ALL your work ASAP and logout of the system."
Comments