0

I want to create a user with adduser command and then set up its password using passwd command.

I want to specify the group, home directory and gecos for the user and then set up the password for the user using passwd command.

If I have stored string values for username, group, home directory, gecos, password in variables un, grp, hd, g and pd respectively, how can I use adduser and passwd commands to create a user with specified information. I know there's another command "useradd" but I want to use "adduser" at this point. How to do this in a shell script?

  • This answer is old, but it should still work (has answers for both useradd and adduser): stackoverflow.com/questions/2150882/… – ajgringo619 Aug 28 at 4:31
  • @ajgringo619 thanks. What should I do about creating user with group, home directory and gecos as arguments? – Ali Aug 28 at 5:50
1
useradd --home /path/to/home \
    --ingroup groupname \
    --gecos "Stuff" username

passwd username

https://manpages.debian.org/jessie/adduser/adduser.8.de.html

  • I want to know how to do it using adduser. – Ali Aug 28 at 6:07
  • actually its adduser, i just typed useradd for whatever reason i dont know... If you would have opened the manpage you would have seen it tho.. – RolfRisiko Aug 28 at 6:25

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.