Introduction
Both useradd
and adduser
commands create new users on a Linux system. Although the two commands perform a similar task, the execution method is different.
Whether you're just testing how the system works or if you're a system administrator that handles user provisioning, knowing how useradd
and adduser
work is crucial in choosing between the two commands.
This guide outlines the main differences between useradd
and adduser
commands and when to use them.
Prerequisites
- Access to the terminal.
- A sudo user to run the commands.
What is useradd Command?
useradd
is a Linux command for creating a new user. It requires various options to add and set up an active user account. Additionally, the command allows changing default values for the user creation process.
useradd
is a low-level, portable command available on all Linux distributions.
useradd Example
To see how useradd
works, run the following command in the terminal:
sudo useradd <username>
Replace <username>
with a name for the new user. For example:
After entering the sudo password, the command creates a new user with the username test_user and doesn't produce an output. useradd
automatically applies preconfigured options from the /etc/useradd file. However, the user requires additional setup with the passwd command to use the account.
To view all the available options, use the -h
tag:
useradd -h
Alternatively, use the man command to view the complete manual page.
What is adduser Command?
The adduser
command creates a new user on a Linux system through an interactive prompt. The high-level wrapper is written in Perl and is a front-end for useradd
.
Running the command creates a home directory, adds the default shell as Bash, and prompts the user to enter a password to unlock the account.
However, the command doesn't provide much control over the user creation details. Additionally, adduser
is unavailable on all Linux distributions and, therefore, not portable.
adduser Example
To see how adduser
works, run the following command in the terminal:
sudo adduser <username>
Replace <username>
with a name for the new user. For example:
The command starts a program that guides the user through the creation process in an interactive interface. The command creates an active user account on the system.
To view all the options with brief descriptions for the adduser
command, run:
adduser -h
useradd vs. adduser
The main difference between the useradd
vs. adduser
commands is in how the two commands execute:
- The
useradd
command is lower level and available on all Linux distributions. It requires additional parameters to set up the account entirely. - The
adduser
command is higher level and not available on all Linux distributions. The command adds a user to the system with standard settings.
useradd vs. adduser: Which One Should You Use?
The useradd and adduser commands add a new user to the system but differ in execution.
The adduser
command is convenient for setting up a regular user with standard presets, such as a password and Bash shell. adduser
provides guides through the user creation process in an interactive prompt. Therefore, the adduser
command is a beginner-friendly way to add a new user.
The useradd
command provides complete control over the user creation process. With additional options, useradd
achieves the same tasks as adduser
. As an additional benefit, the command is portable across different Linux systems and more convenient for Bash scripting.
Note: Regardless of how the user was created, you can modify an existing user with the usermod command.
Conclusion
After reading about the differences between the useradd
and adduser
, you know when to use which command. Both commands add a user account to a Linux system, and adduser
serves as a front-end for useradd
.
Next, check out our Linux command cheat sheet, which features more commands for users and groups.