newusers – For Creating Multiple Users at Once in Batch Mode

The newusers command is a Linux utility that allows the creation of multiple user accounts simultaneously. It reads a file that contains a list of usernames, passwords, and other user account information, and creates the user accounts according to the specifications provided in the file. This is particularly useful in situations where a large number of user accounts need to be created in a short amount of time, such as in educational institutions or companies.

Overview

The syntax for the newusers command is as follows:

newusers [options] <filename>

The options argument is optional and can be used to modify the behavior of the command. The <filename> argument is required and should contain a list of user account information in the following format:

username:password:UID:GID:gecos:home_dir:shell

Each line in the file represents a new user account to be created. The fields in the line are separated by colons (:). The fields are defined as follows:

  • username: The name of the user account.
  • password: The encrypted password for the user account. If this field is empty, the user account will be created with no password.
  • UID: The user ID for the user account. If this field is empty, the next available UID will be assigned.
  • GID: The group ID for the user account. If this field is empty, the default group for the user will be used.
  • gecos: The GECOS field for the user account. This field can contain any additional information about the user.
  • home_dir: The home directory for the user account. If this field is empty, the default home directory will be used.
  • shell: The login shell for the user account. If this field is empty, the default shell will be used.

Examples

Create multiple user accounts from a file:

$ cat users.txt
user1:password1:::::
user2:password2:::::
user3:password3:::::
$ newusers users.txt

Create a user account with a specific UID and GID:

$ echo "user4:password4:1001:1001::::" > users.txt
$ newusers users.txt

Options

The available options for the newusers command are as follows:

Option Description
-h, --help Display help information and exit.
-V, --version Display version information and exit.
-u, --uid-start Specify the starting UID for the first user in the file. Subsequent users will be assigned the next available UID.
-g, --gid-start Specify the starting GID for the first user in the file. Subsequent users will be assigned the same GID.
-s, --system Create system accounts.
-c, --comment Specify the GECOS field for the user accounts.
-D, --default Use default values for any fields that are not specified in the file.
-N, --no-user-group Do not create a group with the same name as the user account.
-r, --root Specify an alternate root directory for the home directories of the user accounts.

Troubleshooting tips

  • If the newusers command fails to create any user accounts, check the syntax of the input file to ensure that it is correct.
  • If the password field is left blank, the user account will be created with no password. This may pose a security risk, so it is recommended to set a password for each user account.
  • If the UID field is left blank, the next available UID will be assigned. However, if a specific UID is required, it should be specified in the input file to avoid conflicts with existing user accounts.

Notes

  • The newusers command requires root privileges to run.
  • The input file should be created with a text editor and saved as a plain text file.
  • Usernames should be unique and not already exist on the system.