
newusers Command in Linux
The newusers command in Unix and Linux is used to update and create new users in batch mode. It reads a file containing the user name and clear-text password pairs and uses this information to update existing users or create new ones.
This commandline utility is designed for large system environments where multiple accounts need to be updated or created at once. It streamlines the process and ensures consistency.
Each line is in the same format as the standard password file (/etc/passwd) with the following exceptions −
- pw_passwd − This field contains the clear-text password for the user. The password will be encrypted and stored as the new encrypted password for the user.
- Pw_age − This field represents the password age (how long the password has been set). For users with shadow passwords, this field is ignored if the user already exists.
- pw_gid − This field specifies the group ID. If it contains the name of an existing group, the user will be added to that group. If it contains a non-existent numerical group ID, a new group with that ID will be created.
- pw_dir − This field specifies the user's home directory. The directory will be checked for existence. If it does not exist, a new directory with the specified name will be created. The ownership of the directory will be set to the user being created or updated.
This file /etc/login.defs contains configuration settings for the shadow password suite, which may affect how newusers operates. In addition, the input file contains unencrypted passwords. It is crucial to protect this file to prevent unauthorized access.
Table of Contents
Here is a comprehensive guide to the options available with the newusers command −
Syntax for the newusers Command
The following is the general syntax for the newusers command −
newusers [options] [file]
Options for the newusers Command
The following are different options that allow you to customize the behavior of the newusers command to suit your specific needs −
Tag | Description |
---|---|
-b, --badname | Allows the creation of usernames that do not meet the usual naming standards. Normally, usernames must follow specific rules regarding characters and length, but this option relaxes those constraints. |
-r, --system | Creates system accounts. These accounts typically have lower user IDs and are used for system processes and daemons rather than for regular user logins. |
-R, --root CHROOT_DIR | Specifies a directory to chroot into. This means the newusers command will operate within the given directory as if it were the root directory. This is useful for creating or modifying users in a different root environment, such as when preparing a new system installation. |
-h, --help | Displays the help message for the newusers command and exits. This is useful if you need a quick reference for the command's options and usage. |
Examples of the newusers Command
In this section, we'll show you how to use the newusers command with various options to manage user accounts efficiently in different scenarios.
Creating or Updating Users from a File
In this example, we'll walk through the process of creating or updating users using the newusers command and a file named users.txt.
To get started, first create the users.txt file with the following content −
echo "neville:password123:1001:1002:Neville Smith:/home/neville:/bin/bash" > users.txt
Each line in the file contains −
- Username: neville
- Password: password123 (this will be encrypted)
- UID: 1001
- GID: 1002
- Gecos: Neville Smith
- Home Directory: /home/neville
- Shell: /bin/bash
Next, run the following command to create or update users −
sudo newusers users.txt
By running this command, you instruct the system to read the users.txt file and either create new users or update existing ones based on the details provided. The password will be encrypted, and all specified attributes like UID, GID, home directory, and shell will be set accordingly.

Allowing Bad Names with the newusers Command
First, create a file named users_badname.txt with the following content −
echo "badname_user:Str0ngPass\!456:1001:1001:Bad Name User:/home/badname_user:/bin/bash" > users_badname.txt
Next, run the following command to create users with usernames that do not meet the usual naming standards −
sudo newusers --badname users_badname.txt
By running this command, you instruct the system to allow the creation of usernames that don't meet the usual naming standards, such as those containing underscores or other special characters.

Creating System Accounts with the newusers Command
To create system accounts, you can simply use the newusers command with the --system option −
First, create a file system_users.txt with the following content −
echo "sysuser:Str0ngPass\!456:101:101:System User:/home/sysuser:/bin/bash" > system_users.txt
Run the command −
sudo newusers --system system_users.txt
By running this command, you instruct the system to create system accounts that typically have lower user IDs and are used for system processes.

Conclusion
The newusers command in Unix and Linux offers a streamlined, efficient way to manage user accounts in batch mode, making it especially valuable for system administrators in large environments.
By reading a file with user details, it allows for the creation or updating of multiple accounts simultaneously. This utility is highly flexible, supporting options like --badname for unconventional usernames, --system for system accounts, and --root for operating in chroot environments. Additionally, it ensures secure practices by encrypting passwords and referencing the /etc/login.defs file for default configurations.
Whether creating system accounts, updating user details, or operating silently for scripting purposes, newusers is a versatile and indispensable tool for effective user management.