3

When doing this on Ubuntu server 14.04:

camilstaps@localhost:~$ sudo useradd --home-dir /var/www/xxx.camilstaps.nl/ --no-create-home --root /var/www/xxx.camilstaps.nl/ --shell /bin/sh xxx

I'm getting the error:

useradd: cannot lock /etc/passwd; try again later.

I checked and tried the following (found the suggestions all over the internet):

  • Obviously, I'm using sudo
  • There exists a file /etc/.pwd.lock, but it is empty and removing it doesn't help
  • There are no other *.lock files in the /etc directory
  • The filesystem is not full (14G available on /)
  • Rebooting the server doesn't remove the lock.

I'm stumped. How can I unlock /etc/passwd?


df -ih output

camilstaps@localhost:~$ df -ih
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/vda1        1,3M  228K  1,1M   18% /
none             125K     4  125K    1% /sys/fs/cgroup
udev             124K   404  123K    1% /dev
tmpfs            125K   386  124K    1% /run
none             125K     5  125K    1% /run/lock
none             125K     1  125K    1% /run/shm
none             125K     2  125K    1% /run/user
  • Have you tried adduser instead of useradd? – heemayl Feb 16 '15 at 16:04
  • what are the permissions of /etc/passwd ? is your partition mounted ro ? – Panther Feb 16 '15 at 16:04
  • @heemayl that does work, however, adduser doesn't have the possibility to set a user's root directory. Is there a way to do adduser and then change the root directory? – user125111 Feb 16 '15 at 16:05
  • @bodhi.zazen rw-r--r-- - what do you mean with your second question though? – user125111 Feb 16 '15 at 16:06
  • 1
    This sometimes can happen when your disk is full as well. What does df -i show with regards to inode usage on the / filesystem? – Aaron D Feb 16 '15 at 23:49
0

Found this and this solves the problem

You need to remove all the four files and then try

/etc/passwd.lock
/etc/shadow.lock
/etc/group.lock
/etc/gshadow.lock

Logging as the root user

$ sudo su 
rm –rf /etc/passwd.lock
rm –rf /etc/shadow.lock
rm –rf /etc/group.lock
rm –rf /etc/gshadow.lock

Then try your command.

camilstaps@localhost:~$ sudo useradd --home-dir /var/www/xxx.camilstaps.nl/ --no-create-home --root /var/www/xxx.camilstaps.nl/ --shell /bin/sh xxx
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy