adduser vs useradd in Linux

All Linux systems have access to hundreds or thousands of different commands. Some of these commands serve similar purposes, though there is usually a particular tool that is more suited for certain jobs. Such is the case with the adduser and useradd commands on Linux.

Although these commands provide the same general function, one is a high level utility for adding new user accounts, and the other is a low level utility for adding new user accounts. If you are not sure what that means, do not worry, we will explain everything.

In this tutorial, you will learn the difference between the adduser and useradd commands in Linux. You will also see command examples of how to use both tools, and see what kind of scenarios is appropriate for one or the other.

In this tutorial you will learn:

  • What is the difference between adduser and useradd
  • In what situations is it better to use adduser or useradd
  • How to use adduser or useradd commands through examples
adduser vs useradd in Linux
adduser vs useradd in Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux system
Software adduser, useradd (default commands)
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

What is the difference between the adduser and useradd commands?

To put it simply, adduser is the command meant for the Linux user, and useradd is the command meant for system use. In technical terms, this means that adduser provides a high level interface for adding new users, and useradd provides a low level interface.

The two commands basically perform the same functions, but adduser is easier to use and has some user friendly features, like an interactive prompt that asks you for information about the new user account you are trying to add. Since adduser is designed for a Linux user, it does not cause much fuss when developers update it or introduce their own implementations of it. Only the user is affected. On the other hand, useradd receives fewer updates and needs to remain backward compatible. System functions and scripts rely on the predictability of useradd.

So, that explains why both commands are necessary. Confusion arises because the commands are easily mixed up and function mostly the same. You will find a lot of documentation and guides that tell the user to execute one or the other, and use the two commands almost interchangeably. Furthermore, useradd is the older of the two commands and remains more consistent across various Linux distros, so some users may prefer to use it, even though it is less user friendly than adduser.

As an average Linux user, you should use adduser when you are adding new users to your system. If you are a developer, useradd is what you will use in the scripts or programs you create, to ensure compatibility across different distros and future updates.

Executing the adduser and useradd commands to add two new users - do you see the differences?
Executing the adduser and useradd commands to add two new users – do you see the differences?

Observe the screenshot above for a moment, where we use both the adduser and useradd commands to add a new user account to our system. As you can see from the output, the adduser commands prompts us for relevant information to configure the user account, and gives some output indicating the user creation process.

On the other hand, useradd gives us absolutely no output (which actually means the user creation was successful). To configure a password afterwards, we need to execute the passwd command, whereas useradd asks us for this information by default.

Command examples for adduser and useradd

You can learn how to use the adduser and useradd commands by opening a command line terminal and executing either command with root privileges. Follow along with some of the examples below to learn the syntax of both commands.

adduser command examples

  1. To add a new user to the system, normally you will not need to specify any additional options. Just provide the name of the user you wish to add – in this case, testuser.
    $ sudo adduser testuser

    This will spawn a prompt to ask you basic user information, and use the distro’s settings provided in /etc/adduser.conf to apply to the new user.

  2. To add a new system user, rather than a normal user account, append the --system option.
    $ sudo adduser --system testuser
  3. Add a new user group by using the --group option and providing the name of the group you wish to add. In this case, the name is testgroup.
    $ sudo adduser --group testgroup
  4. To configure the new account with a different home directory than the default, use the --home option and provide the path to the new user’s home directory. In this example, we will use the /home/accounts/testuser directory.
    $ sudo adduser --home /home/accounts/testuser testuser 
  5. If you do not want to set a new password on the user, append the --disabled-login option in your adduser command.
    $ sudo adduser --disabled-login testuser
  6. Configure some system shell other than the default by using the --shell option. Provide the path to the shell in your command – in this case, /bin/sh.
    $ sudo adduser --shell /bin/sh testuser

useradd command examples

  1. To create a new user, simply specify the name of the user in your useradd command.
    $ sudo useradd testuser

    Note that unlike the adduser command, this will not prompt you for additional information. A password will not be configured and a home directory will not be automatically created. To configure a password, proceed in running the passwd command.

  2. If you want the useradd command to create a new home directory for your user, you will need to append the -m option.
    $ sudo useradd testuser -m
  3. To configure a custom home directory for the new user, you will need to use the -m option like in the previous example, but also add the -d option and specify the new path to the home directory.
    $ sudo useradd testuser -m -d /home/accounts/testuser
  4. Add the -s option to your command to specify the default shell for the user. This is the shell they will be presented with every time they login. In this example, we will use /bin/sh.
    $ sudo useradd -m testuser -s /bin/sh

You can always use the man command to read more about the adduser and useradd commands and their official documentation. Click the previous link to see how to open the manual pages for any command on a Linux system.

Closing Thoughts

In this guide, we learned about the differences between adduser and useradd. We also saw command examples for both tools. To summarize, adduser is the user-side replacement for useradd. Both commands are relevant and will continue to exist, since one is ideal for high level functions and the other one for low level.