How to Kill a User Session on a Linux Server

Aside from being mean or pulling a joke, there aren’t many times when you’d need to end another user’s session.

If a user logs in but doesn’t log out, it’s a good idea to end their session so that their account isn’t open to anyone else. 

You can stop this from happening by telling SSH to automatically log out users who haven’t done anything for a certain amount of time.

Another, more important reason to end a user’s session is to stop damage from being done by someone who has taken over the user’s account. 

Some bad scripts could also run when rogue users log in. 

With one command, you can end all of the processes that belong to that user. 

Use a command called pkill to do this.

To delete a single user account from your dedicated server, for example, you would type as root:

pkill -9 -u username

Once the user session is over, you should take steps to make sure that whatever caused it doesn’t happen again. 

That could mean forcing the user to change the password, limiting access to SSH, locking the account, or even deleting the user.

There are other ways to use the pkill command, and when used with other Linux tools, it is a very powerful command to know. 

Type “man pkill” into the command line or read the online documentation to find out more about it.