adduser Command in Linux



The adduser is a versatile command that allows you to create a new user or group on Linux. This command provides a high-level interface for the adduser command and offers interactive prompts while making the user account.

The adduser command simplifies the process of user creation and customization and removes the need to set everything separately for the user on Linux. You can add a user account, set the password for the user account, and add other required information with a single command.

Table of Contents

Follow this tutorial to find different usage and examples of adduser commands in Linux systems.

How to Install adduser Command in Linux?

By default, adduser command is installed on most Linux systems. However, in case you experience adduser command not found error, install the command from the Linux repository using −

sudo apt install adduser -y
adduser Command Linux 1

After installation, run the version command provided below to confirm adduser command is installed on the Linux system −

adduser --version
adduser Command Linux 2

Syntax for the adduser Command

The basic syntax to use the adduser command on Linux is given below −

sudo adduser username

In the above syntax, if you are a regular user, you must use sudo with the adduser command followed by the username you want to add. If you logged in as a root user, you can use the adduser command without sudo privileges.

Different Options Available for the adduser Command

By default, the adduser command creates a new user without any additional options or flags. However, you can change the adduser command behavior by adding options before the username. In the following table, we have added a description of some options you can use with the adduser command on Linux −

Options Description Example
--home Specifies a custom home directory for a new user. sudo adduser --home /custom/home/dir jenny
--no-create-home Prevents the creation of a home directory for a new user. sudo adduser --no-create-home jenny
--shell Sets a custom login shell for a new user. sudo adduser --shell /bin/zsh jenny
--disabled-password Creates a new user without setting a password (disable password login). sudo adduser --disabled-password jenny
--debug Displays information about debugging sudo adduser --debug jenny
--quiet Suppresses most output and makes the process less verbose. sudo adduser --quiet jenny
--ingroup Add the new users to the existing group sudo adduser --ingroup groupname jenny
--force-badname Allows username creation that does not follow the NAME_REGEX configuration variable. sudo adduser --force-badname 012jenny

Examples of the adduser Command in Linux

As previously mentioned, the adduser command is a versatile Linux command that can be used in different ways. This can be possible only if you add options or flags with the adduser command.

On Linux, you can use the adduser command to −

Let’s discuss these examples one by one to help you understand them in a better way.

Creating a User in Linux

By default, the adduser command, if used without an option, will prompt you to enter the information for the new user. It will add a new user, and select the UID/GID by default from the range of 1000 to 59999. Further, it will also add your user to the new group with the same name as the username and create a home directory for the user.

Here, as an example, we are adding a user johnny on Linux from the below-provided adduser command −

sudo adduser johnny

When you execute the above adduser command, it will do some addition manually. However, it will ask you to enter the password for your username according to your choice. Ensure setting a strong password to increase the privacy of your user account on Linux.

adduser Command Linux 3

When the password is successfully updated for your new user account, it will then ask you to enter the new value. You can write them according to your choice, like full name, room number, work phone, home phone, and others. You can skip them by pressing the Enter button on each value −

adduser Command Linux 4

Once everything is done, simply reply with Y argument to confirm the information provided for user account creation was correct −

adduser Command Linux 5

This will add the user to your Linux system −

adduser Command Linux 6

Note − You can switch to a new user using the su command followed by your username on your current terminal sessions. You can also switch to your newly created user account from the system login page.

Creating a User with a Specific Login Shell

The login shell is a command interpreter that a user uses when they log in. By default, the same login shell is selected if you use the adduser command without an option. However, if you want to create a user with a specific login shell other than your default one, you can use the following syntax −

sudo adduser username --shell /bin/sh

Replace the username with the actual username you want to create and /bin/sh with the path to the desired shell (for example, /bin/bash for Bash).

The following example will create a user named linux by setting the default shell as bash −

sudo adduser linux --shell /bin/sh
adduser Command Linux 7

Use the same instructions as previously followed to complete adding the user with a specific shell on Linux.

adduser Command Linux 8

Note − It should also be noted that you cannot use a username like 123linux, ab@linux, or another such type of name with the default adduser command. If you do this, you will get an error because these usernames will not match the regular expression configured through the NAME_REGEX configuration.

adduser Command Linux 9

However, you can avoid this error and use such names by adding the --allow-bad-names option with the adduser command, as provided in the table above.

Creating a User with a Different Configuration File

The default configuration file for the adduser command on Linux is /etc/adduser.conf. When you execute the adduser command, it works based on the default values specified in the configuration file. However, if you have a custom configuration file, you can add the --conf option with the adduser command followed by the file name.

As an example, we have a custom configuration file with the name custom_config.conf. And, we are creating a user jonny with this configuration file using the following command −

sudo adduser jonny --conf custom_config.conf
adduser Command Linux 10

Create a User with a Specific Directory

Like other tasks, the adduser command automatically creates the default directory for your username. However, you can change the directory and choose your specific director for your username using the following syntax −

sudo adduser username --home /home/path/to/directory

Here, as an example, we are creating a user jon with a specific directory /home/carter using the following command −

sudo adduser username --home /home/carter
adduser Command Linux 11

Creating a User without a Home Directory

You can also create a user without the default home directory on Linux by using the following syntax −

sudo adduser --no-create-home username

Here, we have created a user jenn through the adduser command without a home directory using the following command −

sudo adduser --no-create-home jenn
adduser Command Linux 12

Creating a System User

By default, the adduser command creates a regular user that has limited access to work with the Linux system. However, you can create a system user and perform system-wide tasks using the --system flag with the adduser command. The syntax to add the system user with the adduser command on the Linux system is provided below −

sudo adduser --system username

Here, we have created a system user jenny with the following adduser command on Linux −

sudo adduser --system jenny
adduser Command Linux 13

Note − After creating the system user, you can set the password for this user using the following sudo passwd command −

sudo passwd username

Creating a User without a Password

If you want to create a user without a password on Linux with the adduser command, you can do it by adding the --disabled-password option. The syntax for creating a user without a password is provided below −

sudo adduser --disabled-passwd username

Here, the following command creates a user tom without a password −

sudo adduser --disabled-passwd tom
adduser Command Linux 14

Creating a New User Group

Apart from creating a user, you can also use the adduser command to create a user group on Linux. It can be possible by adding the --group option with the adduser command, the syntax is provided below −

sudo adduser --group group_name

Here, a group named mygroup is created using the following command −

sudo adduser --group mygroup
adduser Command Linux 15

In this way, you can work with the adduser command on Linux.

Conclusion

The adduser command is a powerful command that is pretty useful in creating a new user on Linux with a strong password. You can use different options like --shell, --conf, --home, --system, and more to change the behavior of the adduser command. You can create a user with a specific shell, configuration file, custom directory, without a password, and others. Besides that, you can also create a system user and a group apart from the regular user with the adduser command.

A complete detail to perform all the aforementioned actions with the adduser command is provided in the above section of this blog. Go follow them and start creating multiple users on Linux to protect your data from unauthorized access.

Advertisements