How do you lock a user account using the 'passwd' command?

QuestionsQuestions8 SkillsProUser Account ManagementAug, 26 2025
0341

To lock a user account using the passwd command in Linux, you can use the -l option. This effectively disables the user's ability to log in by placing a '!' in front of the user's password hash in the /etc/shadow file. Here’s how to do it:

  1. Open a terminal.

  2. Run the following command, replacing username with the name of the user account you want to lock:

sudo passwd -l username

For example, to lock a user account named john, you would use:

sudo passwd -l john
  1. To verify that the account has been locked, you can check the /etc/shadow file:
sudo grep username /etc/shadow

You should see an entry for the user with a '!' at the beginning of the password field, indicating that the account is locked.

To unlock the account later, you can use the -u option with the passwd command:

sudo passwd -u username

This will remove the '!' and restore the user's ability to log in.

0 Comments

no data
Be the first to share your comment!