1

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?

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

1 Answer 1

1
useradd --home /path/to/home \
    --ingroup groupname \
    --gecos "Stuff" username

passwd username

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

2
  • I want to know how to do it using adduser.
    – Ali
    Aug 28, 2019 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, 2019 at 6:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .