Bash – How to Add Users Non-Interactively

bashuseradd

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

user:serve
password: spoot
group: sortaNotMega

user:watcher
password: spoogle
group: notMega

Best Answer

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 be 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

Related Question