Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Create Multiple User Accounts in Linux?
Adding a single new user to a Linux system can be achieved through the useradd command. However, system administrators often need to add many users at once. Linux provides the newusers command for bulk user creation from a file.
Syntax
sudo newusers user_details.txt
Where user_details.txt is the file containing the details of all the usernames to be added.
User Details File Format
The user details file follows a specific format with colon-separated fields ?
UserName:Password:UID:GID:comments:HomeDirectory:UserShell
Creating the User Details File
Let's create a file with multiple user entries ?
$ cat MoreUsers.txt uname1:pwd#@1:2112:3421:storefront:/home/uname1:/bin/bash uname3:pwd#!@3:2112:3525:backend:/home/uname3:/bin/bash uname4:pwd#$$9:9002:4721:HR:/home/uname4:/bin/bash
Setting File Permissions
Before using the user details file, we should set proper permissions for security ?
sudo chmod 0600 MoreUsers.txt
This ensures only the root user can read the file containing passwords.
Checking Existing Users
Let's verify the current users in the system by checking the /etc/passwd file ?
tail -5 /etc/passwd
pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false ubuntu:x:1000:1000:ubuntu16LTS,,,:/home/ubuntu:/bin/bash
Running the newusers Command
Now we run the newusers command to add the users from our file ?
sudo newusers MoreUsers.txt
Verifying Added Users
Let's verify that the users were successfully added ?
tail -10 /etc/passwd
pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false saned:x:119:127::/var/lib/saned:/bin/false usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false ubuntu:x:1000:1000:ubuntu16LTS,,,:/home/ubuntu:/bin/bash uname1:x:2112:3421:storefront:/home/uname1:/bin/bash uname3:x:2112:3525:backend:/home/uname3:/bin/bash uname4:x:9002:4721:HR:/home/uname4:/bin/bash
Key Points
- The
newuserscommand creates users, groups, and home directories automatically - Passwords in the file should be encrypted or will be stored as plaintext initially
- Always set restrictive permissions (0600) on files containing user credentials
- Verify UID and GID values don't conflict with existing users
Conclusion
The newusers command provides an efficient way to create multiple user accounts from a structured text file. Always ensure proper file permissions and verify the results after bulk user creation.
