Nov 10, 2018

How to stop user from logging to a Linux system

passwd -l <user>
doesn't stop all possible means of logging in. For example, if they log in using ssh with public keys they can still login as they won't need a password.

To disable an account you should use
usermod --expiredate 1
This set the account expire date to 1970

Another way to stop the user logging in again, edit the /etc/passwd file and remove the user or change the 7th column to /sbin/nologin.

The user may currently already login, See also:

How to log out a user from Linux System