To log out a user automatically in Linux, you can use the pkill
command. For example, to log out the user username
, you would run the following command:
pkill -KILL -u username
This will immediately terminate the user's session and log them out of the system.
Alternatively, you can use the logout
command to log out a user. This command is similar to the exit
command, which is used to log out of a terminal session, but it can be used to log out other users as well. To log out the user username
using the logout
command, you would run the following:
logout username
Keep in mind that you will need to have sufficient privileges to log out other users. If you do not have the necessary permissions, you will receive an error message.