5

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
11
  • Have you tried adduser instead of useradd?
    – heemayl
    Feb 16, 2015 at 16:04
  • what are the permissions of /etc/passwd ? is your partition mounted ro ?
    – Panther
    Feb 16, 2015 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, 2015 at 16:05
  • @bodhi.zazen rw-r--r-- - what do you mean with your second question though?
    – user125111
    Feb 16, 2015 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, 2015 at 23:49

2 Answers 2

1

You can use adduser instead of useradd. adduser also provides an interactive session to configure your Linux user and also creates the necessary /home/username/ directory automatically.

sudo adduser <username>

By the way, there is no difference between adduser and useradd. They both serve the same purpose.

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

You must log in to answer this question.