Introduction
The adduser
command in Linux creates a new user or group. By applying various options, adduser
allows customizing settings in the user provisioning process. The command is a high-level interface for useradd and features interactive prompts when creating new accounts.
This article shows how to install and use the adduser
command in Linux.
Prerequisites
- A system running Linux.
- Access to the command line/terminal.
- Access to the root user or a sudo user.
Install adduser
The adduser
command is not available by default on all Linux systems. To install the adduser program, run one of the following commands for the appropriate OS:
- Ubuntu/Debian:
sudo apt install adduser
- CentOS/RHEL:
sudo yum install adduser
Check that the command is available after installation with the following:
adduser --version
The output shows the program version and the license details, indicating a successful installation.
adduser Syntax
The basic syntax for the adduser
command is:
sudo adduser <options> <username>
By default, the command adds a user based on the preconfigured options in the /etc/adduser.conf file.
Linux adduser Options
The adduser
command has several working modes and behaves differently based on specified options and parameters. Below is a table with commonly used options and their descriptions.
Option | Description |
---|---|
--system | Adds a system user or group. |
--conf <file> | Uses <file> instead of the /etc/adduser.conf. |
--disabled-login | Disables logging into the user account. |
--disabled-password | Disables logging in using a password. |
--gid <ID> | Sets the group ID number to <ID> . If the user is specified, it also adds the user to the group. |
--group | Runs the addgroup command and adds a user group. If --system is specified, it adds a system user and group. |
--home <directory> | Sets the user's home directory to <directory> . |
--shell <shell> | Uses <shell> as the user's login shell. |
--ingroup <group> | Adds user to <group> instead of the default group in the configuration file. |
--no-create-home | Avoids creating the home directory for the user. |
For a full list of options and details, use the man command.
adduser Examples
Running the adduser
command starts interactive prompts, which guide you through the user creation process. The results of the adduser
command depend on the specified options.
Add a Regular User
The most basic way to use the adduser command is without any options. For example:
sudo adduser <username>
The command automatically:
- Creates the user with the provided username and the first available UID (1000 and greater).
- Makes a group with the same name and uses the first available GID.
- Adds the user to the group.
- Creates a home directory for the user (/home/<username>).
- Starts the passwd command to set up the user's password.
- Asks for additional user details.
The newly created user appears on the user list in the /etc/passwd file. List all users and grep the new user with the following command:
sudo cat /etc/passwd | grep <username>
The output lists the user entry and all the additional user information.
Add a System User
System users are non-login user accounts used for installation processes and services. To add a system account, use the following syntax:
sudo adduser --system <username>
The command does the following:
- Creates a new system user with the first available system UID (1-999).
- Adds the user to the nogroup group.
- Creates a home directory for the user (/home/<username>).
The system user appends to the /etc/passwd file.
Add Group
The adduser
command with the --group
option adds a new group to the system. The combination invokes the addgroup
command. For example:
sudo adduser --group <group name>
The command is the same as running the following:
sudo addgroup <group name>
Adding the --system
option creates a system user and group with the same name. For example:
sudo adduser --group --system <name>
The UID and GID are between 1 and 999, indicating it is a system user and group.
Add User Password Options
Additional adduser
options allow overriding the default password rules set in /etc/adduser.conf.
For example, to avoid setting a password during user creation, run:
sudo adduser --disabled-login <username>
The command does not request setting up a password and disables logging into the account until using the passwd
command.
To disable password login for the user, use the following command:
sudo adduser --disabled-password <username>
If you disable password login, use SSH, for example, to access the system with your account.
Note: To modify existing users, use the usermod command.
Add a User With a Custom Shell
To set the default login Linux shell for the user, use the --shell
option and provide the path:
sudo adduser --shell=<shell path> <username>
The provided shell overrides the default options and becomes the login shell for the given user.
Add a User Home Options
To add a user and set a custom home directory path, run the following:
sudo adduser --home <directory> <username>
Use this option to have different users share a home directory location.
Alternatively, to create a user without creating a home directory, run the following:
sudo adduser --no-create-home <username>
The command avoids creating a home directory for the user, which is suitable for system users.
Conclusion
You've learned how to use adduser
to add new users to a Linux system. The adduser
command is a simple and user-friendly way to add new accounts.
Next, see the detailed comparison between the useradd and adduser commands.