How to lock multiple accounts?

QuestionsQuestions8 SkillsProUser Account ManagementAug, 23 2025
0188

To lock multiple user accounts in Linux, you can use a loop in the command line. Here’s a concise way to do it:

Using a Loop in Bash

You can create a list of usernames and then loop through that list to lock each account. Here’s an example:

for user in user1 user2 user3; do
    sudo passwd -l $user
done

Breakdown:

  • for user in user1 user2 user3;: This initializes a loop that iterates over each username.
  • sudo passwd -l $user: This command locks the password for each user in the list.

Example:

If you want to lock accounts for joker, batman, and superman, you would modify the command as follows:

for user in joker batman superman; do
    sudo passwd -l $user
done

Important Note:

Make sure to replace user1, user2, and user3 with the actual usernames you want to lock.

Further Learning

For more advanced user management techniques, consider checking out the "Linux User Management" labs on LabEx, which provide practical exercises on managing user accounts.

If you have any more questions or need further assistance, feel free to ask!

0 Comments

no data
Be the first to share your comment!