To lock a user account in Linux, you can use the passwd command with the -l option. This prevents the user from logging in by disabling their password. Here’s how to do it:
-
Open a terminal.
-
Run the following command, replacing
usernamewith the actual username of the account you want to lock:sudo passwd -l username
This command will lock the user account by adding a ! in front of the password hash in the /etc/shadow file.
To verify that the account is locked, you can check the password status with:
sudo passwd -S username
If the account is locked, the output will indicate that the password is "locked."
To unlock the account later, you can use:
sudo passwd -u username
This will remove the lock and allow the user to log in again.
