How to Create Multiple User Accounts in Linux

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
  • pw_passwd: user’s password
  • pw_uid: user’s ID
  • pw_gid: user’s group ID
  • pw_gecos: defines comments sections.
  • pw_dir: 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
Create Multiple User Accounts in Linux
Create Multiple User Accounts in Linux

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"
Verify User Accounts in Linux
Verify User Accounts in Linux

For more information, see the newuser man page.

$ man newuser 

You might also like to check these following related articles.

  1. 3 Ways to Change a Users Default Shell in Linux
  2. How to Create a Shared Directory for All Users in Linux
  3. Whowatch – Monitor Linux Users and Processes in Real Time
  4. How to Send a Message to Logged Users in Linux

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.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 thought on “How to Create Multiple User Accounts in Linux”

  1. Five new users should be created, and each user should be new in the system. The users’ UIDs should be specified in the file and be in the range of 5001 to 5005. The primary group name should be the same as the user’s login name. The user’s full name can be whatever you like. The home directory should be /home/username, and the user’s default shell should be /bin/bash.

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.