[Solved] groupadd fails with “cannot lock /etc/group; try again later”

I am connected to an Ubuntu 12.04.3 LTS server via SSH; when I try to add a group, I get the following message:

groupadd: cannot lock /etc/group; try again later.

In researching this problem, I found some suggestions to look for and remove a .pwd.lock file in the same directory. I found such a file, created over a year ago; I removed it but this did not change the behavior of groupadd.

I’ve read Cannot lock ‘/etc/group’ in recovery mode but I am not booted into recovery mode and all partitions are mounted read-write. I am not logged in as the root user.

Enquirer: Air

||
Solution #1:

The error message is technically correct but the “try again later” message is misleading. The real issue here is hidden in an error message from adduser:

[email protected]:/$ adduser existinguser newgroup
adduser: Only root may add a user or group to the system.

To add a new group when logged in as a non-root user, you must use sudo:

[email protected]:/$ sudo groupadd newgroup
[sudo] password for host:
[email protected]:/$ grep 'newgroup' /etc/group
newgroup:x:1013:
[email protected]:/$
Respondent: Air
Solution #2:

I just found myself getting this message during a Docker build.

I solved it very easily by adding this directive before the privileged commands in the Dockerfile:

USER root
Respondent: Mike Robinson
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.