How to Add Multiple Users in Linux
If you need to know how to add multiple users in linux, the fastest approach is usually a shell loop or a small script that runs useradd or adduser for each account. Linux does not have one universal built-in “add multiple users” command, but you can create several accounts efficiently with a loop, a file-driven list, or a short admin script.
Quick answer
To add multiple users in Linux, run a command like useradd or adduser once per username, usually inside a loop. For a few accounts, a shell loop is simplest. For larger batches, it is better to read usernames from a file and create each account automatically. After that, set passwords, verify home directories, and confirm group membership.
Method 1: Create multiple users with a shell loop
This is the easiest method when you only need to create a small number of accounts. It works well if you already know the usernames.
Prepare the list of usernames. For example:
alice bob carolRun a loop with
useradd.for user in alice bob carol; do sudo useradd -m -s /bin/bash "$user" doneThis creates each user, makes a home directory with
-m, and sets/bin/bashas the default shell.Set passwords for each account. You can do this one by one with
passwd, or use a safer batch method shown below.
This method is straightforward, but it is best for small batches. If you are managing dozens of accounts, a file-driven approach is easier to maintain.
Method 2: Create users from a file
For larger batches, store usernames in a plain text file, one per line. This makes it easier to reuse, edit, and audit the list.
Step 1: Create a text file with usernames
Example file named users.txt:
alice
bob
carol
davidStep 2: Read the file and create accounts
while IFS= read -r user; do
[ -z "$user" ] && continue
sudo useradd -m -s /bin/bash "$user"
done < users.txtThis loop skips blank lines and creates one user at a time. If a username already exists, useradd will fail for that entry and continue to the next line unless you stop the script manually.
Optional: Create users with a default group
If you want all new users to belong to the same primary group, you can specify it during creation:
sudo useradd -m -s /bin/bash -g staff aliceReplace staff with a valid group on your system. If the group does not exist, create it first.
Set passwords for the new accounts
Creating the account does not always set a password. In many systems, the account will exist but remain inaccessible until a password is assigned or another authentication method is configured.
Interactive password setting
For a few users, the simplest method is:
sudo passwd alice
sudo passwd bob
sudo passwd carolThis is safe because the password is entered interactively and is not exposed in shell history.
Batch password setting without exposing plaintext in the terminal
If you need to set passwords for multiple users, avoid typing plain passwords directly in the command line. One practical approach is to use a temporary password file that you protect carefully, then remove after use.
Example using chpasswd:
printf '%s\n' \
'alice:StrongPass1!' \
'bob:StrongPass2!' \
'carol:StrongPass3!' | sudo chpasswdThis is convenient, but be careful: the passwords appear in the command itself. A safer operational choice is to place the username-password pairs in a protected file, run chpasswd from that file, and then delete the file immediately after.
Example from a file named passwords.txt:
alice:StrongPass1!
bob:StrongPass2!
carol:StrongPass3!
sudo chpasswd < passwords.txt
shred -u passwords.txtUse the secure deletion approach only if it fits your environment and storage policies. In many cases, interactive password assignment or forced password changes at first login is a better option.
Choose home directories, shells, and groups
When creating users in Linux, the account is more useful if you configure the basics correctly from the start.
Home directory
The -m flag tells useradd to create a home directory, such as /home/alice. Without it, the account may exist but have no home directory.
sudo useradd -m aliceDefault shell
Use -s to choose the login shell. A common choice is /bin/bash, but some systems use different shell paths.
sudo useradd -m -s /bin/bash aliceIf the shell path is invalid or not installed, the user may be unable to log in correctly. Always confirm that the shell exists on your system.
Primary group
You can assign users to a specific primary group with -g:
sudo useradd -m -g developers aliceIf you want to add users to supplementary groups as well, use -G:
sudo useradd -m -G sudo,docker aliceThis is useful when new accounts need access to admin tools, shared project files, or application-specific permissions.
useradd vs adduser
Both commands can create users, but they are not identical.
| Command | Typical behavior | Best use |
|---|---|---|
useradd | Low-level command, available on most Linux systems, often requires flags for home directory, shell, and other defaults | Scripts, automation, and consistent admin workflows |
adduser | Higher-level helper on Debian and Ubuntu-based systems, usually interactive and more user-friendly | Manual account creation on Debian-family systems |
On many Debian and Ubuntu systems, adduser is a friendlier wrapper around account creation. On RHEL, CentOS, Fedora, and similar systems, admins often use useradd directly. If you want a script that works broadly, useradd is usually the safer choice because its behavior is more consistent across distributions.
Verify the users were created
After creating multiple users, check that the accounts exist and that the settings are correct.
Check /etc/passwd
getent passwd alice bob carolThis confirms that the accounts were added to the system account database.
Check home directories
ls -ld /home/alice /home/bob /home/carolThis helps verify that the home directories were created and assigned properly.
Check group membership
id alice
id bob
id carolThis shows the user ID, primary group, and supplementary groups for each account.
Confirm password and shadow file status
User password hashes are stored in /etc/shadow, not in plain text. If a password has been set, the account should be ready for login according to your authentication policy.
Common problems and fixes
Username already exists
If useradd reports that a username already exists, skip that account or choose a different name. Check with:
getent passwd usernamePermission denied
Creating users requires administrative privileges. Run the command with sudo or switch to the root user if your environment allows it.
Missing shell path
If the shell specified with -s does not exist, the user may not be able to log in. Confirm the shell path before creating the account:
ls /bin/bash /bin/shNo home directory created
If you forget -m, the account may be created without a home directory. You can create it later, but it is simpler to include the flag during account creation.
Users cannot log in
Check whether a password was assigned, whether the shell is valid, and whether the account is locked or restricted by policy. Also verify that SSH or console access is configured correctly if the user is trying to log in remotely.
Best practices for creating multiple Linux users
- Use
useraddin scripts for predictable behavior across distributions. - Use
adduserwhen you want a more guided, interactive experience on Debian-based systems. - Create a home directory for each user unless you have a specific reason not to.
- Choose a valid shell and group structure before creating the accounts.
- Set passwords securely, ideally without exposing them in shell history or terminal output.
- Verify the result with
getent,id, and directory checks.
Frequently Asked Questions About how to add multiple users in linux
How do I add multiple users at once in Linux?
Use a shell loop or script that runs useradd or adduser once for each username. For a small list, a one-line loop is usually enough.
Can I use a script to create multiple Linux users?
Yes. A shell script is one of the best ways to automate user creation, especially when you need to repeat the same settings for many accounts.
What is the difference between useradd and adduser?
useradd is the lower-level command and is common in scripts. adduser is often more interactive and user-friendly on Debian and Ubuntu systems.
How do I set passwords for multiple users in Linux?
You can run passwd for each user interactively, or use chpasswd for batch updates. Avoid exposing passwords in shell history or plain text whenever possible.
How do I create users from a list in Linux?
Put one username per line in a text file, then read the file in a while loop and run useradd for each entry.
Do I need root access to create users?
Yes, you need administrative privileges. Most systems use sudo for this task.
Conclusion
The most practical way to handle how to add multiple users in linux is to use a loop or script with useradd or adduser, then confirm passwords, home directories, and group memberships. For a few accounts, a simple shell loop is enough. For larger batches, a file-driven workflow is easier to maintain and less error-prone. If you standardize the shell, home directory, and group settings from the start, account creation becomes faster and easier to verify.
