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
  • 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? –  Feb 16 '15 at 16:05
  • @bodhi.zazen `rw-r--r--` - what do you mean with your second question though? –  Feb 16 '15 at 16:06
  • He's asking if the root filesystem is mounted read-only. Check: `mount | grep ' / '` – muru Feb 16 '15 at 16:12
  • @muru alright, thanks - the output: `/dev/vda1 on / type ext4 (rw,errors=remount-ro)` - so I guess it's not, but when an error occurs it is? I can write other files in the /etc directory normally. –  Feb 16 '15 at 16:14
  • @CamilStaps: You can use `adduser` and then change the `/etc/passwd` entry manually to make the desired directory (using proper permissions) as the home directory for the user, although i have not checked it. – heemayl Feb 16 '15 at 16:15
  • @heemayl thanks - how do I exactly edit /etc/passwd then? Because http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/ doesn't show where the root directory is stored. I tried `usermod`, but it says `user 'xxx' does not exist`... –  Feb 16 '15 at 16:20
  • @CamilStaps: I see. you are trying a `chroot` dir. – heemayl Feb 16 '15 at 16:21
  • 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
  • @AaronD thanks, I added the output of that comment to my question - looks good to me though, only 18% is in use. The whole disk is 20G. –  Feb 17 '15 at 08:48

2 Answers2

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.

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
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
Trect
  • 324
  • 4
  • 12