A root user can logout and kill any user session forcefully using the following commands:
a) pkill command – Kill processes by name.
b) kill command – terminate or signal a process.
c) logout command – Logout of a login shell. This command can be used by normal users to end their own session.
logout command syntax and example
If you are logged in as nixcraft user and just wanted to exit a login shell type the following command or hit CTRL+D:
$ logout
You will be logout of a login shell session or secure shell session.
Task: Linux logout all other users
If you would like to logout other users, you must login as root user. Next you need to use the pkill command.
pkill command syntax
The syntax is:
pkill -KILL -u {username} |
Warning: Do not kill root user or other system level user process. The following example, will kill all process on your server. Do not run the pkill for root user:
pkill -KILL -u root
To see list of logged in user type who or w command:
# who
OR
# w
To logout a user called raj, enter:
# pkill -KILL -u raj
OR
$ sudo pkill -KILL -u raj
See also
- For more information read our previous “Linux kill and logout users” tutorial.
- Man pages: pkill(1),w(1),who(1),pgrep(1)
Thankssssss man !
Its one of things i hardly ever remember, never mind that i take the effort to write it down, but if you do need it a post like this is worth a million…
thanks
Works in OpenBSD 4.5 also. Great tip.
Whow, thanks for this posting! Just what I needed, highly appreciated!
Thanks, I was looking for such a command
i want to show the login time and logout time of all users then i will sort it according to their name help me pls…
Thanks a lot!
pkill worked fine in the GUI session!
Regards;
Thanks a lot.
I found here very usefull information about my quistions.
Best regards.
what’s the KILL flag do?
thanks, it works me to kill my locked sessions in a server
Hey, Thanks… This is exactly i requried.
Thanks you buddy….I have seen some of your posts regarding Linux commands. They are very useful for beginners like me.
if i logged twice from putty as same user root then if i want to logout one root user then how i would do it.As same user logged twice then in that case if i kill process of root -user then both will get kill…so is their is any ip based parameter to logout one root ?
Mark! do the work!
Wow. What bad information. Lets say you have root logged in under two sessions.
pkill -KILL -u root
That kills all processes owned by root. Meaning most system processes.
Let’s say you have one user in multiple sessions and that user is not root. Well, you just killed both sessions, even if that’s not what you wanted.
This is terrible advice, and the article should be called “Linux Kill All Processes by User”, and have nothing to do with “logging off”.
how The system should send an email alert when the root user has logged out from ssh/terminal.
@Scott, if you know the better command how to logout the user you could write it here, not just come and start wonder here how bed info that is!
How to identify which roles are running in Linux server by using Command line.
How to remotely GUI access linux gateway server ???????????
I want to be able log multiple users off with a message without shutting down. Any thoughts?
Thanks
Thank MAN!!!
ThanKs, comes handy when dude forgot to log out of his guest session here!
Yeah first time i found a usefull answer to my linux questions, : Ctrl + D
:D