Adduser Command usage in Linux with Examples

Adding users in Linux using the graphical interface is an easy task. But what about the command line? There are many users who either have only CLI or prefer to use commands for adding a new user. 

We can use the adduser command to create new users. With adduser, not only the user itself is created, but also the other necessary settings are made, such as creating a home directory, assigning the user to a group, setting the login shell, etc. Although it a command line command, but the creation of the user is interactive.

adduser is typical for all distributions based on Debian, RedHat, and other Linux. Let’s see how to install and use it.

Adduser Installation

adduser command will already be included on all Linux systems. Therefore, we don’t need to install it. Yet, if you don’t have this command tool on your system then here is the way to install it.

For Debian or Ubuntu users

sudo apt install adduser

For RedHat, Fedora, Rocky, and other similar Linux:

sudo dnf install adduser

Usage

The general syntax of adduser is quite simple:

sudo adduser <options> <username>

For example: If you want to add a user named – h2s the above command will be:

sudo adduser h2s

This is followed by a short, interactive dialogue in which you are first asked for the password and then for the full user name. The following questions about room number, telephone number, etc. are more interesting for companies (or date back to the time when Linux was always a pure server system with remote login) and can all be answered without input by pressing ⏎ (Enter) answered.

As mentioned above, a group with the same name is automatically created with each user. If you do not specify any options, as in the example above, adduser uses the default settings stored in the file /etc/adduser.conf. Then the default configuration files (e.g. for the Bash) are copied from the directory /etc/skel into the home directory of the new user.

Adduser command Linux example

Adduser Options

Of course, adduser also knows a number of options. Some of them are:

OptionDescription
--force-badnameallow usernames that do not match the
NAME_REGEX[_SYSTEM] configuration variable
--confuses the FILE file as the configuration file instead of /etc/adduser.conf
--homeThe home directory is created in “path/to/directory” instead of in the directory stored in the configuration file. If the directory does not exist, it is created, the files from /etc/skel are copied there as well.
--no-create-homeno home directory is created for the user
--ingroup GRUPPEThe user is added to the GROUP group instead of the preset group in the configuration file.
--disabled-loginWhen setting up the user, a password is not asked and the account is marked as inactive. The user cannot log on to the system.
--disabled-passwordWhen setting up the user, the password is not requested. The user cannot log in to the system until a password is set using the passwd command. This is useful, for example, if you as a system administrator do not want to know the user’s password.
--shell SHELLIt is not the shell stored in the configuration file that is created as the login shell, but the shell specified in the option. The full path must always be specified, e.g. . If you specify, no login shell is created, which also means that this user cannot connect to the computer via SSH.--shell /bin/zsh--shell /bin/false
--uid IDGives the new user the desired ID, if it is not already in use.

adduser knows a number of other options, which can be found on the man page.

AddUser Command Example

Let’s now learn some usage of adduser command to know how to create a new system user, group, delete existing user, and more.

How to add a new user:

To add a standard user on Linux, we can use the terminal and the command given below:

sudo adduser user-name

Replace the user-name with whatever you want.

The command will not only create a user but also a group with the same. It will ask users to enter the password to make it secure. Along with other information such as Fullname, work number, and more… Linux uses the UID (user identifier) value 1000 or greater than that for standard users.

How do you check the user has been added to our system? For that either we can log in to the system with it or can check the /etc/passwd file where all users of our Linux are listed.

To List all users, type:

sudo cat /etc/passwd

To login with newly created user:

su new-user-name

How to add a Linux system user?

Linux “System user” can also be added using the adduser command, however, instead login, the “System user’ mainly use to manage the services and Linux assigns UID (user identifier) to such users between (1-999).

sudo adduser --system user-name

The above command will create a user with a “non-group” group and home directory.

How to delete a user?

If you have created a user then definitely at some point in time you would need to delete it as well. So, here is the command that helps us to remove the existing Linux user permanently.

sudo deluser user-name

The command will ask for your current sudo user password that’s it.

How to disable user Login

There is an adduser option known as –disable-login that we can use to create a user but without any login option. Because the command will not create a password for it.

sudo adduser --disabled-login user-name

However, later if you want to login it, can use the passwd command to create a password for it.

Disable password Usage

Let’s say you want to create a new user on your system to log in only using the SSH and want to disable the usage of plain password then here is the command syntax to follow:

sudo adduser --disabled-password user-name

Custom home directory

By default the system will create a user’s file directory under our Linux’s Home. If you want to change that to assign some custom location then use:

sudo adduser --home /path user-name

Note: Replace /path with the custom diorecotry path and user-name with your name of new user you want to create.

Whereas you can also create a user without home directory, using:

sudo adduser --no-create-home user

Replace user with whatever you want to create.

These were few usage of adduser command that we can use on almost all popular Linux system using the command terminal. Whether it is Desktop with GUI or CLI, the commadns will work on all of them.

Other Articles:

How to install Deepin Terminal on Ubuntu 22.04 LTS
7 Best Gnome system monitor alternative Linux applications
5 Best htop alternatives to monitor Linux systems

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.