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
- In what situations is it better to use
- How to use
useraddcommands through examples
|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
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – 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,
adduseris the command meant for the Linux user, and
useraddis the command meant for system use. In technical terms, this means that
adduserprovides a high level interface for adding new users, and
useraddprovides 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
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
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.
Observe the screenshot above for a moment, where we use both the
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
useraddcommands 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
- 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,
$ sudo adduser testuser
This will spawn a prompt to ask you basic user information, and use the distro’s settings provided in
/etc/adduser.confto apply to the new user.
- To add a new system user, rather than a normal user account, append the
$ sudo adduser --system testuser
- Add a new user group by using the
--groupoption and providing the name of the group you wish to add. In this case, the name is
$ sudo adduser --group testgroup
- To configure the new account with a different home directory than the default, use the
--homeoption and provide the path to the new user’s home directory. In this example, we will use the
$ sudo adduser --home /home/accounts/testuser testuser
- If you do not want to set a new password on the user, append the
--disabled-loginoption in your
$ sudo adduser --disabled-login testuser
- Configure some system shell other than the default by using the
--shelloption. Provide the path to the shell in your command – in this case,
$ sudo adduser --shell /bin/sh testuser
useradd command examples
- To create a new user, simply specify the name of the user in your
$ sudo useradd testuser
Note that unlike the
addusercommand, 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
- If you want the
useraddcommand to create a new home directory for your user, you will need to append the
$ sudo useradd testuser -m
- To configure a custom home directory for the new user, you will need to use the
-moption like in the previous example, but also add the
-doption and specify the new path to the home directory.
$ sudo useradd testuser -m -d /home/accounts/testuser
- Add the
-soption 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
$ 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.
In this guide, we learned about the differences between
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.