How to logout a user on Linux

Endrit Qerreti

Endrit Qerreti

Logging users out of your system is easy, all you need to have is the username that you want logged out, and you can log them out using the methods we explained below.

In this tutorial, you will learn how to logout an user on Linux.

Step 1 - View logged in users

To view the logged in users that are logged in on your server, you can use the w command. Simply run the command below, and it will list all users that are currently connected to your server, this includes all sessions active and inactive sessions that might not be active being used by a user, but the session appears as active because the connection was disconnected.


Alternatively, you can also use the who command, if you want to see only the logged in usernames


The difference between two commands is that, w will display more information about logged in users, while who displays mainly the username of the logged in user and the time of login

Step 2 - Logout

Let's say you are logged in as user owlhowto on your server, or your computer, and you want to logout this user, then you can do so by running the command below


Alternatively, you can also use the shortcut CTRL + D to logout, instead of the logout command


Note: logout command should only be used when you want to logout from your session, if you want to logout another user from your server, then you cannot use the logout command, in this case you need to use the pkill command.

To logout other users from your server, you can use the command below. The syntax of pkill command is

sudo pkill -9 -u owlhowto

Replace: owlhowto with the username of the account that you want to logoff. Now, you can view the logged in users again to verify that the user was logged out from the system.


Note: Do not use the pkill on root account as it will kill all root processes, if in case you accidentally did this, reboot your server so the processes that were terminated by the pkill command will restart again once server gets booted again.


In this tutorial, you learned how to logout an user on Linux, by using the pkill command to logout other users, and logout command when logging out your session.