The “adduser” Command in Linux [12 Practical Examples]

Linux is a multi-user OS that allows several users to interact with the system simultaneously. As a system administrator, one will be responsible for managing the system’s users and groups by adding and deleting users and designating them into various groups. A new user or group can be created in Linux using the adduser command. It also enables changing user provisioning settings by applying various options. In this article, I will describe all the features and uses of the adduser command in Linux.

A. Description

The adduser command can be used to add a new user to your present Linux system. With this command, you will also be able to change the settings for the user that will be created.

B. Syntax

The adduser command in Linux is a built-in command that takes options and USER as its argument. The general syntax for using adduser commands is given below.

adduser [OPTION] USER

Note: In the above syntax, the OPTION is enclosed by a square bracket which means that OPTION is not mandatory for the command.

C. Options

One or more options can be added to the syntax of the adduser command to modify the command. I have listed some useful options below. If you do not find your desired option you can check the man (manual) page.

man adduser

Useful Options

  • –disabled-login (option does not ask to set a password for a new user. The user won’t be able to use the account until the password is set)
  • –disabled-password (Like –disabled-login, but logins are still possible (for example using SSH RSA keys) but not using password authentication)
  • –group (Creates a group)
  • -h/–help (Display brief instructions)
  • –home (Add a User with a Different Home Directory)
  • –firstuid ID (Override the first uid in the range that the uid is chosen from (overrides FIRST_UID specified in the configuration file)
  • –lastuid ID (Override the last uid in the range that the uid is chosen from ( LAST_UID))
  • –shell (Add a User with a Different Shell)
  • –system (Create a system user or group)
  • -u/–uid ID (Force the new userid to be the given number. adduser will fail if the userid is already taken)
  • –version (Display version and copyright information)

Note: All options are case-sensitive. You must be careful while using these.

Practical Examples of the “adduser” Command in Linux

The adduser command in Linux helps to manage the system’s users and groups by adding and deleting users and designating them into various groups. A few real-life examples of the adduser command are given below.

Example 1: Add a New User Using the “adduser” Command in Linux

Creating multiple user accounts in Linux is very common. This command will add a new user to your Linux system. It will ask for some details, and a new user account will be created after entering them. Here, I will create a user named tyan. To do so, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser tyan

➌ Now, press the ENTER button.

Output >

A new user named tyan is created in the following image.

adduser command in linux has created a user named tyan.


Similar Readings


Example 2: Add a User With a Specific Shell Using the “adduser” Command in Linux

Sometimes, creating a new user account with a different shell is necessary. The default shell is /bin/bash for new users in ubuntu. Here, I will create a new user account with the /bin/sh shell, skipping the other details. To do so, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser rick --shell /bin/sh

➌ Now, press the ENTER button.

➍ After that, Type the following command to check the shell:

grep rick /etc/passwd

➎ Now, press the ENTER button.

Output >

In the following image, you can see a new user named rick is created with a different shell.

adduser command in linux has created a user named rick in a specific shell.

Example 3: Add a User With a Different Home Directory

You can create a user with a different home directory. Here I will create arsenal user account with a different home directory (/home/football). To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser arsenal --home /home/football

➌ Now, press the ENTER button.

Output >

In the following image, you can see arsenal user account is created with the /home/football home directory.

adduser command in linux has created a user named arsenal within home directory named football

Example 4: Create a User Without Home Directory

You can create a user account without creating a home directory using the adduser command along with the –no-create-home option. Here I will create a user account named lee without creating a home directory. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser --no-create-home lee

➌ Now, press the ENTER button.

Output >

In the following image, you can see with the help of the –no-create-home option home directory for the new user lee has not been created.

adduser command has created a user named lee with the help of the --no-create-home option, home directory for the new user lee has not been created.

Example 5:  Add New User With a Specified User ID Using the “adduser” Command in Linux

You can create a new user account specifying an individual user ID using the adduser command with option -u. Here I will create a new user account specifying a user ID 16101. To do so, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser -u 16101 bean

➌ Now, press the ENTER button.

➍ Type the following command in the command prompt to confirm whether the user contains the specific user ID.

id bean

➎ Now, press the ENTER button.

Output >

The following image shows that a new user named bean has been created. The user ID of the bean user account is displayed on the terminal.

adduser command in linux has created a user named bean with a specific user ID

Example 6: Add New User With a Specific Group ID Using the “adduser” Command in Linux

You can create a user with a specific group ID. Here I will create a user named morty and add it to a group named mortygroup of specific group ID: 1007. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser --gid 1007 morty

➌ Now, press the ENTER button.

➍ To check the group ID of morty, type the following command in the command prompt

id morty

➎ Now, press the ENTER button.

Output >

In the following image, you can see the morty user account is created and added tp a group named mortygroup of specific group ID: 1007.

adduser command in linux has created a user named morty assigning it to a specific group ID which is 1007

Example 7: Add a New System User Using the “adduser” Command in Linux

You can create a new system user using the adduser command and the –system option. Here I will create a system user account named messi. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser -- system thiago

➌ Now, press the ENTER button.

Output >

In the following image, you can see thiago user account has been created as a system user. Here you can see its UID is below 1000(130 in my case) which means that it is a system user account.

adduser command has created a user named thiago as system user.

Example 8: Create a User With Disabled Login Set-up

You can create a user account by skipping setting the password initially using the adduser command but the user can not log in without setting the password. Here, I will create a user account named tik without setting a password initially. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser --disabled-login tik

➌ Now, press the ENTER button.

Output >

In the following image, you can see by using the –disabled-login option, command prompt does not ask to set a password for the new user. However, The user won’t be able to use the account until the password is set.

adduser command has created a user named tik with the option disabled login

Example 9: Create a User Without a Password Using the “adduser” Command in Linux

You can create a user account without setting the password using the adduser command. Here, I will create a user account named peter without a password. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser --disabled-password peter

➌ Now, press the ENTER button.

Output >

In the following image, you can see by using the –disabled-password option, the command prompt does not ask to set a password for the new user.

adduser command has created a user named peter with the option disabled password

Example 10: Creating a Group Using the “adduser” Command in Linux

You can create a group using the adduser command in Linux very easily. Here I will create xyz group using the adduser command. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo adduser --group xyz

➌ Now, press the ENTER button.

Output >

In the following image, you can see xyz group has been created.

adduser command has created a group named xyz

Example 11: Display the Help Section of the “adduser” Command

For details about the adduser command in Linux, you can go to the help section of the adduser command very easily. To do so, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

adduser -h

➌ Now, press the ENTER button.

Output >

In the following image, the help section of the adduser command is displayed.

help section of adduser command is shown with the help of -h option

Example 12: Get the Version of the adduser Command

Sometimes, it is necessary to know the version of the adduser command. Here, I will find the version of the adduser command using –version options and the adduser command.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

adduser --version

➌ Now, press the ENTER button.

Output >

The following image shows the version details of the adduser command.

version of adduser command is shown with the help of --version option

Conclusion

In this article, I have tried to demonstrate the applications and effectiveness of the adduser command in Linux. I hope you’ll be competent enough to explore more things with the help of these practical examples.


Similar Readings

Rate this post
Susmit Das Gupta

Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio

Leave a Comment