As a Linux system administrator, you sometimes have to add new user accounts to the system. For this purpose, the adduser command is often used . When it comes to the creation of multiple users, the adduser command can become quite boring and time-consuming. This short article aims to provide Linux system administrators with a simple and unattended way to create users in batches. The newusers command will help you create multiple users by getting information from pre-populated files. |
Require
Privileged access to Linux computers.
Agreement
#- The given command needs to be run with root user privileges or use the sudo command
$- The given command is run as a regular user
how to proceed
Create a file containing usernames
First, you need to create a file containing a list of usernames.
$ vi users-list.txt
In the file, one user per line, here is the style:
Username:Password:User ID:Group ID:User Info:Home Directory:Default Shell Username:Password:User ID:Group ID:User Info:Home Directory:Default Shell Username:Password:User ID:Group ID:User Info:Home Directory:Default Shell ...
Create user
After creating the file containing user information, use the newusers command to create the user.
# newusers users-list.txt
Check user account
Finally you can confirm that the users have been created correctly by viewing them in the /etc/passwd file:
# tail /etc/passwd