The two utilities for adding or creating user accounts in Unix/Linux systems are adduser and useradd. These commands are designed to add a single user account in the system at a time. What if you have multiple users accounts to be created? That’s when you need a program such as newusers.

Newusers is a useful command line utility used to update and create new user accounts at a single time. It is intended to be used in IT environments with large systems where a system administrator needed to update or create multiple user accounts in batch. It reads information from stdin (by default) or a file to update a set of existing user accounts or to create new users.

In this article, we will explain how to create multiple user accounts in batch mode using Newusers utility in Linux systems.

To create users in a batch, you can provide their information in a file in the following format, same as the standard password file:

pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shell

where:

pw_name : username

: username pw_passwd : user’s password

: user’s password pw_uid : user’s ID

: user’s ID pw_gid : user’s group ID

: user’s group ID pw_gecos : defines comments sections.

: defines comments sections. pw_dir : defines the home directory of the user.

: defines the home directory of the user. pw_shell: defines user’s default shell.

Attention: You should protect the input file since it contains unencrypted passwords, by setting the appropriate permissions on it. It should only be readable and writable by root.

For example, to add the user accounts ravi and tecmint, you can create a files called users.txt as shown.

$ sudo vim users.txt

Next, add the user accounts details in the file in the following format.

ravi:213254lost:1002:1002:Tecmint Admin:/home/ravi:/bin/bash tecmint:@!#@%$Most:1003:1003:Tecmint:/home/tecmint:/bin/bash

Save the file and set the required permissions on it.

$ sudo chmod 0600 users.txt

Now run the newusers command with the input file to add the above user accounts at once.

$ sudo newusers users.txt

First, newusers program tries to create or update the specified accounts, and then write these changes to the user or group databases. In case of any errors except in the final writes to the databases, no changes are committed to the databases. This is simply how the newusers command works.

If the previous command is successful, check the /etc/passwd and /etc/groups files to confirm that the user accounts have been added as shown.

$ cat /etc/passwd | grep -E "ravi|tecmint"

For more information, see the newuser man page.

$ man newuser

You might also like to check these following related articles.

In this article, we’ve explained how to create multiple users in Linux using newusers program. Use the feedback form below to ask any questions or share your comments with us. If you know of any similar utilities out there, let us know as well.