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:
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements pkill
Est. reading time 2m
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
# w
To logout a user called raj, enter:
# pkill -KILL -u raj
$ sudo pkill -KILL -u raj

See also

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 23 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
23 comments… add one
  • rajdoe Dec 12, 2007 @ 1:13

    Thankssssss man !

  • songshu Jul 24, 2008 @ 13:15

    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…

  • The Doctor Jun 12, 2009 @ 1:44

    Works in OpenBSD 4.5 also. Great tip.

  • Wildcard Sep 2, 2009 @ 0:13

    Whow, thanks for this posting! Just what I needed, highly appreciated!

  • Husen Jun 7, 2010 @ 10:55

    Thanks, I was looking for such a command

  • harris Mar 5, 2011 @ 2:49

    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…

  • Mehdi May 6, 2011 @ 17:09

    Thanks a lot!
    pkill worked fine in the GUI session!

  • Mohamad Aqashenas Sep 14, 2011 @ 13:48

    Thanks a lot.
    I found here very usefull information about my quistions.
    Best regards.

  • yaw Oct 6, 2011 @ 15:02

    what’s the KILL flag do?

  • arturo Apr 16, 2012 @ 3:58

    thanks, it works me to kill my locked sessions in a server

  • Raj May 14, 2012 @ 12:08

    Hey, Thanks… This is exactly i requried.

  • New_Linux_kid Jun 15, 2012 @ 5:18

    Thanks you buddy….I have seen some of your posts regarding Linux commands. They are very useful for beginners like me.

  • shivendra Aug 24, 2012 @ 5:32

    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 ?

  • sunnogo Aug 27, 2012 @ 15:18

    Mark! do the work!

  • Scott Apr 8, 2013 @ 16:16

    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”.

  • nusantara Aug 15, 2013 @ 11:39

    how The system should send an email alert when the root user has logged out from ssh/terminal.

  • Kreso Nov 8, 2013 @ 10:35

    @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!

  • Raaz Jul 7, 2015 @ 10:17

    How to identify which roles are running in Linux server by using Command line.

  • Raaz Jul 7, 2015 @ 10:18

    How to remotely GUI access linux gateway server ???????????

  • Shaun Apr 13, 2016 @ 14:24

    I want to be able log multiple users off with a message without shutting down. Any thoughts?


  • José Oliveira Jun 27, 2016 @ 10:49

    Thank MAN!!!

  • kozaki Jul 6, 2016 @ 17:55

    ThanKs, comes handy when dude forgot to log out of his guest session here!

  • Benjamin Mar 28, 2017 @ 14:49

    Yeah first time i found a usefull answer to my linux questions, : Ctrl + D

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum