Solution Linux Useradd Error - cannot lock /etc/passwd; try again later

October 12, 2012 | By
| 3 Replies More

Sometime in Linux when adding user using the useradd command it throws below error.

#useradd test
useradd: cannot lock /etc/passwd; try again later


The system files that are related to Linux user management are,

/etc/passwd : Contains user account information
/etc/shadow: Contains secured account information (encrypted password)
/etc/group : Contains group account Information
/etc/gshadow : Contains secured group information (encrypted group password)

When you create or modify a user, some lock files will get created to prevent concurrent modification of these system files. The lock files are,


These files should get automatically removed once the command “useradd” or “usermod” finishes. Sometimes, you may encounter situations (bugs) where some of these files may not get properly unlocked after the execution of the command. In that case, when you execute useradd next time, it may show the error “cannot lock /etc/password” or “unable to lock group file”. So, if you get any such errors, check for any lock files under /etc.

# cd /etc
# ls –l *.lock

If you find any lock files named passwd.lock, shadow.lock, group.lock or gshadow.lock, remove it.

# rm –rf /etc/passwd.lock
# rm –rf /etc/shadow.lock
# rm –rf /etc/group.lock
# rm –rf /etc/gshadow.lock

Now, you should be able to execute useradd without any errors.


Tagged With : ,

Free Linux Ebook to Download

Comments (3)

Trackback URL | Comments RSS Feed

  1. Mathlon says:

    You should also ensure that your file system has not gone into read-only mode. That will definite cause an issue.

  2. J says:

    I know this is old, but I thought I'd share my experience. It helped me with a batch userdel script I was working on that kept giving me that lock error. The "ls -L" method you mentioned didn't find them all. There was a stray .pwd.lock file in /etc that the following command found:

    find / -type f -name "*.lock"

    Once I removed it, the script worked. Thanks!

  3. Ratata says:

    Nope, removing the *.lock files broke it completely:
    *** Error in 'newusers': double free or corruption (!prev): 0x00007f968a371c70 ***

Leave a Reply

All comments are subject to moderation.