How to Logout a User on Linux
Knowing how to logout a user in Linux is vital to maintaining a healthy operating system. You might need an ex-employee you want removed from the system, or you have identified a rogue user logged in. Luckily the process of logging out the user is very straightforward.
We will also go into detail about logging out your user from the system if you are using SSH. This process is easy and will help close an SSH connection to your server correctly.
You must be careful when you log out a user as any unsaved work will be forced closed. Double check the spelling is correct, and you are logging out the correct user.
You will need to look at other tutorials for logging out of a Linux GUI desktop environment, as the logout process can vary heavily between different operating systems.
The tutorial below will now take you through everything you need to know to log out a user. Also, if you are interested, knowing how to log out of your current session might be handy.
Using the who and pkill Command to Logout a User
This section will cover how you can use the who command to find a user that you can logout using the pkill command. You can use this method to log out any user you want, as long as you have the correct permissions.
It is important to never use the pkill command or its variants on the root user as it is likely to cause system instability.
1. We can use the who command to view all users currently logged into the system. Using this data, we can select a user to log out of the system.
To use the who command, enter the following line into the terminal.
who
You should see a list of all the users currently logged into the system.
dev@pimylifeup:~$ who
dev pts/0 2022-11-08 04:14 (192.168.0.39)
newUser pts/1 2022-11-08 04:15 (192.168.0.39)
2. To log out a user, use the pkill command with the -u
option. The -u
option specifies we are using the UID or username. This process will kill all processes that are owned by the specified user. We also use -SIGKILL
as this will ensure that the system kills the process.
In our example, we will log out the user named newUser
by entering the following line into the terminal.
sudo pkill -SIGKILL-u newUser
3. You can verify the user is logged out of the system by using the who command.
dev@pimylifeup:~$ who
dev pts/0 2022-11-08 04:14 (192.168.0.39)
The post How to Logout a User on Linux appeared first on Pi My Life Up.