# How to Create Multiple Users in Linux?

When working within complex systems such as within large-scale computer networks or IT operations involving multiple applications or software running simultaneously under different user's control. so, Linux OS offers to create multiple users for your system at once.

### Method 1: Using a Command & Text file to Create multiple Users in Linux.

Step 1: Open the Linux terminal

Step 2: Create **.txt file to write the new user's credentials**

```bash
nano new_users.txt
```

step 3: Type your desired multiple-user information in syntax below.

```bash
user_name:user_password:Uid:Gid:comment:home_dir:def_shell
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683776208436/839241e6-7d7e-432b-853b-0f3b9e560dc8.png align="center")

here, User\_name: user name of the new user to be created

**user\_password:** password for the new user

**Uid:** New user's ID

**Gid**: New user's group ID

**comment:** Comment section or User Full Name

**home\_dir:** User's home directory

**def\_shell:** User's default shell

Step 4: change the **.txt file's permissions** using the following command

```bash
sudo chmod 600 new_users.txt
```

Step 5: Input the password of the currently logged in user.

Step 6: Create desired users by typing the command bleow and press Enter.

```bash
sudo newusers new_users.txt
```

Step 7: Now, check if the desired users are created.

```bash
tail /etc/passwd
```

### Method 2: Using Bash Script to Create Multiple Users in Linux.

Step 1: Open the terminal or Press **CTRL + ALT + T**

Step 2: Create a directory name bin in your home directory

```bash
mkdir bin
```

Step 3: After that , Create a bash Script file inside the bin directory

```bash
nano bin/create_users.sh
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683736504459/59b3e0d0-e67a-490f-b6d5-7a086b27ac10.png align="center")

Step 4: Now, write the following script in the **create\_users.sh** file for creating multiple users in a loop.

```bash
#!/bin/bash

read -p "Enter number of Users to create:" num
echo "------------------------------------------------------"
for (( i=1; i<=$num; i=i+1)); do
read -p "Enter Username no.$i: " uname
sudo useradd $uname
read -p "Enter password for user no.$i? [Y/N] " flag
if [[ "$flag" == "Y" || "$flag" == "y" ]]; then
sudo passwd $uname
echo "Successfully created New User: $uname with password."
echo "------------------------------------------------------"
else
echo "Successfully created New User: $uname without password."
echo "------------------------------------------------------"
fi
done
```

Step 5: To save and Exit from the Script, press **CTRL + S** and **CTRL + X** respectively

Step 6: Now, type the following command to permit the current user in your system.

```bash
chmod u+rwx bin/create_users.sh
```

Step 7: Finally restart your system to add the newly created bin directory to the **$PATH** variable

```bash
sudo reboot
```

Step 8: Now open your terminal or Press **CTRL + ALT + T**

Step 9: Run the previously written script by typing the file name.

```bash
create_users.sh
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683736133890/0c773f0e-acac-42e5-8d75-c79a7b6f1417.png align="left")

Step 10: After entering the data, to check if the desired number of users is created.

```bash
tail /etc/passwd
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683736312691/5c669e77-75ab-4e5b-9b48-d90f779d2a7a.png align="left")

### **Complementary Information**: Adding Multiple Users in a Group

Step 1: Open the Terminal

Step 2: Type the following command

* To create a group for now we are creating a group named "Student"
    

```bash
sudo groupadd Student
```

* To add multiple users type the following command.
    

```bash
sudo gpasswd -M UserA,UserB,UserC Group_Name
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683737307454/c3074ec2-ce7b-438d-baaa-899281d7058e.png align="left")

Step 3: To Check the Group Members

```bash
sudo less /etc/group| grep "Group_Name"
or 
sudo grep Student /etc/group
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683736825379/8d1af833-42c0-4a8c-a059-febae8827ca7.png align="left")

As you can see that the users are inside the group named Student.

That's all for now, Happy Coding!!!.
