Linux Logout user / Logoff User Commands

I am a new Linux sysadmin. I am using Linux on HP server. How do I logout users from my systems? How can I forcefully logoff any user using bash shell on Linux?

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}

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

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.