0

I am using Ubuntu 19.10.I want add a system user with a home directory, and the user won't have any login access or password. I want to accomplish this by running useradd without sudo command.

I gave following permission to the main user using sudo visudo:

main_user ALL=(root) NOPASSWD: \
    /usr/sbin/useradd, /usr/bin/chmod, /usr/sbin/userdel, /usr/bin/setfacl, /usr/sbin/usermod

I have followed answer Creating a user without a password but seems like there is no --disabled-password parameter in useradd. Even there was, would it prevent useradd: cannot lock /etc/passwd; try again later. error, since I believe it won't access into the passwd file.

useradd -d /var/users/general -m general --shell /bin/bash

error:

useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
  • 3
    NOPASSWD does not mean "no sudo" - you'd still need to prefix the useradd command with sudo – steeldriver Jul 7 at 19:19
  • I believe this also stands for userdel since I am getting the same error for it as well – alper Jul 7 at 19:22
  • 1
    sudo is needed because only an admin can create/delete user accounts. It is unrelated to the permissions of the user that is being created/deleted/modified. That's a different setting. – user535733 Jul 7 at 21:05
  • Like a guest User? askubuntu.com/questions/1120448/… – C.S.Cameron Jul 8 at 3:28
  • @C.S.Cameron yes and no. I am actually trying to accomplish kind of a jail with dummy users I created (askubuntu.com/q/1034993/660555). There is only a single user able to login in to system, and running jobs under dummy users forcing, those jobs not to overwrite other users's folders with additional permission (superuser.com/a/1342600/723632). Ex: only a user A have access to /home/A/ and the main user able to run a slurm-script as user- A, which only allows that code to run under /home/A. – alper Jul 8 at 11:58

Your Answer

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

Browse other questions tagged or ask your own question.