3

I'm trying to create multiple users accounts in batch and I have full privilege to /etc/passwd

However, this command

sudo echo "vv1:myUltraSecretPassword" | newusers

always return this error

newusers: Permission denied.
newusers: cannot lock /etc/passwd; try again later. 

I've tried all solutions in post https://superuser.com/q/296373/1100842

such as remove lock file

ubuntu@VM-0-17-ubuntu:~$ sudo rm /etc/passwd.lock
rm: cannot remove '/etc/passwd.lock': No such file or directory
ubuntu@VM-0-17-ubuntu:~$ sudo rm /etc/shadow.lock
rm: cannot remove '/etc/shadow.lock': No such file or directory
ubuntu@VM-0-17-ubuntu:~$ sudo rm /etc/group.lock
rm: cannot remove '/etc/group.lock': No such file or directory
ubuntu@VM-0-17-ubuntu:~$ sudo rm /etc/gshadow.lock
rm: cannot remove '/etc/gshadow.lock': No such file or directory 

and mount remount

sudo mount -o remount,rw /
9

First off, the sudo is needed for the newusers command and not the echo command. You are getting that message of cannot lock because sudo is not passed from the echo command to the newusers command. So, you will need to move the sudo to after the | before newusers.

The layout of the password line in the echo command is missing fields, so you probably would have seen error messages like below if you had the sudo in the right location

newusers: line 1: invalid line
newusers: error detected, changes ignored

From the man page for newusers we can see it shows all the fields required.

DESCRIPTION
       The newusers command reads a file (or the standard input by default)
       and uses this information to update a set of existing users or to
       create new users. Each line is in the same format as the standard
       password file (see passwd(5)) with the exceptions explained below:

       pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shell

There are 7 fields above so that will mean you need 6 :'s. You need to have all the fields separated by a : required to create the new user even if the field is blank.

The command should look like:

echo "vv1:myUltraSecretPassword:::::" | sudo newusers

Hope this helps!

| improve this answer | |
  • 1
    or: sudo newusers < file_with_the_informations or sudo newusers file_with_the_informations – Olivier Dulac Oct 26 at 13:38
  • Any idea why incorrectly formatted input causes such a misleading error? – Barmar Oct 26 at 14:35
  • I didn't write the question. – Barmar Oct 26 at 15:40
  • 1
    It might be more helpful to emphasize the correct use of sudo by explaining that first, rather than bury it in an "also". – Barmar Oct 26 at 15:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.