How to lock a user account?

QuestionsQuestions8 SkillsProUser Account ManagementSep, 20 2025
0165

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:

  1. Open a terminal.

  2. Run the following command, replacing username with 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.

0 Comments

no data
Be the first to share your comment!