Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

With several commands in Linux, I get the error:

cannot lock /etc/passwd; try again later.

Does anybody know how to solve it? Also I don't get in my /etc/shadow directory.

share|improve this question

migrated from stackoverflow.com Jun 13 '11 at 7:45

This question came from our site for professional and enthusiast programmers.

    
you have to raise your user level by using "sudo" or "su" command. –  Raptor Jun 13 '11 at 7:18
2  
Your /etc/shadow directory?!? /etc/shadow should be a file. Please give the exact command you're trying to execute. –  Brian White Jun 15 '11 at 11:04
1  
In my case root filesystem was full :-p –  user116963 Feb 5 '12 at 22:20

6 Answers 6

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).

share|improve this answer
1  
to change password, use " passwd <username> " –  Raptor Jun 13 '11 at 7:21

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>
share|improve this answer

I ran into this when a disk error occurred during a userdel operation and the system had to be rebooted. I needed to delete all four of the following files to proceed:

sudo rm /etc/passwd.lock
sudo rm /etc/shadow.lock
sudo rm /etc/group.lock
sudo rm /etc/gshadow.lock
share|improve this answer

This can also be caused by running out of space on the root filesystem. Use strace to be sure. strace is your friend.

share|improve this answer
    
I've been reading many threads with my problem and that was actually the solution. Should be one of the first things to check when having any filesystem problems, I guess. I'm using df instead of strace though. How would strace help me? Never used it –  erikb85 Apr 14 at 10:11
1  
Well, if you already guessed that the problem might be running out of space, then df can help. But strace will tell you what the error code was when it tried to lock the file, so it should remove the guesswork. The way I usually call strace is strace -f -e trace=file command since this usually gives the most useful results. –  Robin Green Apr 14 at 11:03

A demo of this error on Ubuntu 14.04:

user@mybox:/home$ sudo useradd eric
user@mybox:/home$ userdel eric
userdel: Permission denied.
userdel: cannot lock /etc/passwd; try again later.

sudo gives you the permission to lock it.

user@mybox:/home$ sudo userdel eric
user@mybox:/home$
share|improve this answer

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 /
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.