Cannot lock /etc/passwd; try again later

Solution 1:

If no .lock files are present but you still cannot create a user try the following

sudo mount -o remount,rw /

If logged in as root then use

mount -o remount,rw /

Solution 2:

The user you are running the commands as lack the required privileges. Change to root user by issuing the command

su -

or if you have/use sudo

sudo <command to run>

Solution 3:

If you have -R /some/chroot added to your useradd command, that might be the problem.

I thought it meant that the user would be jailed upon login, but that's not the case. By looking at strace output, I saw useradd chrooted into the specified directory, after which of course it cannot find /etc/passwd anymore. So I'm not sure what the option is for, but there's your (well, my) problem.

Solution 4:

That's because you don't have permissions for those operations

  • You can't read /etc/shadow
  • You can't directly modify /etc/passwd

You can change both files through specialized commands (e.g you can change your password).