newusers Command in Linux with Examples


This tutorial explains Linux “newusers” command, options and its usage with examples.

newusers – update and create new users in batch

Description :


newusers reads a file of user name and cleartext password pairs and uses this information to update a group of existing users or to create new users. Each line is in the same format as the standard password file with the following exceptions :

This field will be encrypted and used as the new value of the encrypted password.
This field will be ignored for shadow passwords if the user already exists.
This field may be the name of an existing group, in which case the named user will be added as a member. If a non-existent numerical group is given, a new group will be created having this number.
This field will be checked for existence as a directory and a new directory with the same name will be created if it does not already exist. The ownership of the directory will be set to be that of the user being created or updated.

This command is intended to be used in a large system environment where many accounts are updated at a single time.

Usage :

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

newusers <filename>


Content of the file <filename> contains the list of users, one per line. Following is the syntax of the parameters to be provided for each user.

<Username>:<Password>:<UID>:<GID>:<User Info>:<Home Dir>:<Default Shell>

Username: User login name
Password: User password
UID: User Identifier
GID: Group Identifier for user’s primary group
User Info: User information like full name, contact information etc.
Home Dir: User’s home directory
Default Shell: User’s default shell



Creating users from a file containing the details of new users as per above given format :

# cat /root/users.txt
tester1:test1@123:600:1530:Test User1,

Let’s execute the newusers command by providing file /root/users.txt as input.

# newusers /root/users.txt

Testing whether users are created or not :


For each new user a new line is inserted in the /etc/passwd file as shown below.

# cat /etc/passwd | grep tester
tester1:x:600:1530:Test User1,

The primary group name for each user is stored in the /etc/group file.

# cat /etc/group | grep tester

‘x’ in the password field indicates that the password is shadowed and stored in the /etc/shadow file as shown below.

# cat /etc/shadow | grep tester

Home folders are created for only two users, tester1 and tester2. For other users, home folder was not specified in the /root/users.txt file.

# ls -ld /home/tester*
drwx------ 2 testuser2 tester  4096 Sep 24 14:05 /home/tester1
drwx------ 2 tester4   tester4 4096 Sep 24 14:05 /home/tester4

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.