Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a set of users I need to add to a new system as part of a BASH script that preps my server. How can I non-interactively add the user, create their home directory, set the group, and enter a default password?

For example, if I needed to add the following users, how would I go about that?

user: node
password: spoon
group: ultraMegaPermissions

password: spoot
group: sortaNotMega

password: spoogle
group: notMega
share|improve this question
Which operating system? On my Linux useradd (different than adduser, but form the same shadow package) handles command line parameters: useradd -p spoon -g ultraMegaPermissions -m node. – manatwork Sep 19 '11 at 14:52
up vote 5 down vote accepted

It's an old question, but curious others can consider the command 'newusers'. This is present on both a RHEL5.5 system and a Ubuntu 12.04 system that I use, so I'd take a guess it will available in the repositories for most distributions.

From 'man newusers'

The newusers command reads a file of user name and clear-text password pairs and uses this information to update a group 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

share|improve this answer
no, that would be easy and obviously silly =) – Prospero Feb 2 '13 at 19:11

Use useradd on Linux, at least.

Use crypt(3) to generate an encrypted password, and then do the following for each:

useradd -m -g [group] -p [crypt output] [user]

-m creates a home directory. -g sets the user's initial login group. -p sets the encrypted password, as returned by crypt(3) (you should note that this option may be unsuitable as the encrypted password will be visible to users listing the processes when the user is being created).

You will probably want to use other options too (at a guess, at least -s), read man 8 useradd for those.

share|improve this answer

If you need manually input user password:

echo -n "Enter $MY_USER password: "
read -sa MY_PASS
echo ${MY_USER}:${MY_PASS}::::/home/${MY_USER}:${DEFAULT_SHELL} | newusers

And if you need it totally non-interactive, just run the last command with clear text password ($MY_PASS), which normally not a good idea

share|improve this answer

In case newuser command do not exists on the server.

You can use take the help of passwd command.

 echo "new_passwd" | passwd  --stdin new_user
share|improve this answer
Does not work on my Ubuntu 14.04 – Champ Jul 28 '15 at 18:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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