
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create Multiple User Accounts in Linux
Adding a single new user to a Linux system can be achieved through the useradd command. But system admins often get request to add many users. So Linux provides a different to do a bulk addition of many users to a system.This is the newusers command.
Synatx
sudo newusers user_deatils.txt user_details.txt is the file containing the details of all the usernames to be added.
User Details
Below we see the structure of user_details.txt file.
UserName:Password:UID:GID:comments:HomeDirectory:UserShell
So we create a file with below details to add many usres.
~$ 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
Giving Permissions to the User Details File
Before we sue the user details file to add new users, we should give permission to it to be read by other processes.
sudo chmod 0600 MoreUsers.txt
Lets verify the existing users in the system by going to the /etc/passwd file.
ubuntu@ubuntu:~$ tail -5 /etc/passwd
Running the above code gives us the following result −
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
Run newusers Command
next we run the newusers command to add these usernames.
sudo newusers MoreUsers.txt
Verify Added Users
Now we verify that indeed those users are added , by going again to the /etc/passwd file.
cat /etc/passwd
Running the above code gives us the following result −
……….. …………. 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