Two Methods To Create Bulk Users In Linux

User account creation is one of the basic task for Linux administrator.

We can easily achieve this by running the useradd command.

But what is the solution if you would like to create the bulk users in Linux?

Is there any ways to perform this action?

Yes, we have option in Linux to perform this action. There are two ways we can achieve this as per my knowledge.

We are going to explain these in this article.

Everyone knows the user information was residing in /etc/passwd file.

It’s a text file that contains the essential information about each user.

When we create a new user, the new user details will be appended into this file.

While creating a new users the below four files will be modified.

  • /etc/passwd: User details will be updated in this file.
  • /etc/shadow: User password info will be updated in this file.
  • /etc/group: Group details will be updated of the new user in this file.
  • /etc/gshadow: Group password info will be updated of the new user in the file.

It can be done through the below two commands.

  • useradd: Create a new user or update default new user information using shell script.
  • newusers: update and create new users in batch.

If you would like to read the related articles about user’s then you can navigate to the following articles.

Method-1: How To Create Bulk User Accounts In Linux Using newusers Command?

The newusers command reads a given file and uses this information to update a set of existing users or to create new users.

Each line is in the same format as the standard password file.

Common syntax for bulk users creation.

# newusers [File_Name]

Before performing this, we need to get the latest GID and UID from the passwd file.

# tail -5 /etc/passwd
gdm:x:121:125:Gnome Display Manager:/var/lib/gdm3:/bin/false

Create a file called user-add.txt and the details should be in the following format. Each user line should be in the separate line.


I have added the five users in the file. List out the users using cat command.

# cat user-list.txt

Run the newusers command with the filename to create bulk users in Linux system.

# newusers user-list.txt

We can double confirm this by running the following command.

# grep "2gadmin\|testuser\|demouser\|sudha\|suresh" /etc/passwd

Method-2: How To Create Bulk User Accounts In Linux Using useradd Command With Shell Script?

Use the below script if you would like to create a multiple users in Linux system.

I have added below three users in the file. Use any file command to List out the users which was there in the file.

# cat user-list1.txt

Create a following small shell script to achieve this.

# vi

for user in `more user-list1.txt`
echo "$user"
useradd $user
echo "$user@123" | passwd --stdin "$user"
chage -d 0 $user

Set an executable permission to file.

# chmod +x

Finally run the script to achieve this.

# sh
Changing password for user user1.
passwd: all authentication tokens updated successfully.
Changing password for user user2.
passwd: all authentication tokens updated successfully.
Changing password for user user3.
passwd: all authentication tokens updated successfully.

We can double confirm this by running the following command.

# grep "user1\|user2\|user3" /etc/passwd

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *