When managing users on a Linux system, two of the most common commands you‘ll use to create new users are useradd and adduser. But what exactly is the difference between these two commands and when should you use each one? Let‘s take a deep dive into these user management tools to understand how they work.
An Introduction to Linux Users and Groups
To understand useradd and adduser, we first need to briefly cover some background on how Linux handles user accounts and groups.
On Linux, each user is identified by a unique user ID (UID) and associated with a primary group ID (GID). The UID and GID are numeric values used to represent that user and group in the system‘s user database.
User accounts are stored in the /etc/passwd file which contains the username, UID, GID, home directory, shell, and other details for each user.
Groups represent collections of users that are granted shared permissions. Groups are defined in the /etc/group file with a numeric GID and list of user members. Users can belong to multiple groups beyond their primary GID group.
When a user logs into a Linux system, their UID and GID tell the system their ownership and permissions for accessing files, running programs, and more.
Now that we‘ve covered some Linux user basics, let‘s look at how useradd and adduser allow us to create these user accounts.
Introducing the useradd command
The useradd command is a low-level utility that allows you to directly create a new user account by specifying their UID, GID, home directory, shell, and other properties as command line options.
Some common useradd options include:
-u UID– Specify user UID-g GID– Specify primary GID-G GID1,GID2– Secondary supplementary groups-m– Create the user‘s home directory-s shell– Set the user‘s login shell-c comment– Gecos field / comment-d homedir– Specify a custom home directory-r– Create a system user without home dir
For example, to create a new user with useradd:
# useradd -m -u 1000 -g users -G wheel,admin -s /bin/bash joey
This creates the user joey with UID 1000, primary group users, and supplementary groups wheel and admin. It creates the home directory at /home/joey and sets the shell to bash.
The main advantages of useradd are that it‘s simple, fast, and portable across all Linux distributions. However, it does not handle any additional setup like creating the home directory or setting a password.
Introducing the adduser command
The adduser command aims to make user account creation easier by providing a friendly interactive prompt that guides you through setting up the complete user environment.
When you run adduser it will ask you a series of questions like:
- Username
- User ID
- Home directory
- Shell
- Expiry date
- Password
- Group membership
It will then take care of creating the home directory, copying default configuration files from /etc/skel, and setting the password you provide.
For example:
# adduser maya
Adding user `maya‘...
# Fill out information for maya
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
User information changed.
Created home directory ‘/home/maya‘.
Copied files from ‘/etc/skel‘ into ‘/home/maya‘.
This interactive setup makes adduser great for quickly creating a fully configured user account with all the necessary directories, files, and settings in place.
The main downside is that adduser is not as portable – some Linux environments may use alternate implementations or lack an adduser command entirely.
Comparing Common Options
| Purpose | useradd | adduser |
|---|---|---|
| Create home directory | -m |
Automatic |
| Set shell | -s |
Interactive prompt |
| Set primary group | -g |
Interactive prompt |
| Set supplementary groups | -G |
-G flag or interactive |
| Set password | passwd after |
Interactive prompt |
| Set comment/description | -c |
Interactive prompt |
| Setup skeleton files | Manual | Automatic |
As seen in this comparison, adduser handles most of the common configuration automatically through its prompts, while useradd requires passing many options and additional steps.
When to Use Each Command
In most general cases, it is recommended to use adduser to add new users interactively. It simplifies the process and ensures everything is setup properly in one go.
However, there are some cases where useradd would be the better option:
- If you need to script or automate user creation without interaction
- If you don‘t want to create a home directory and other defaults that come with
adduser - If you need more advanced customization of UID, groups, shell, etc.
- If your Linux environment does not have
adduserinstalled
For example, you may want to use useradd to create system or application service accounts that do not need interactive shells and home directories. The precise control useradd offers is useful in these cases.
Setting User Passwords
When you create a new user with adduser it will prompt you to enter and confirm the password interactively.
If using useradd, you will need to set the password in a separate step using the passwd command. For example:
# useradd joey
# passwd joey
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
This allows setting or changing passwords easily for users created via either adduser or useradd.
Copying Skeleton Files and Configuration
One difference we noted earlier is that adduser will automatically copy files from /etc/skel into the new user‘s home directory to configure their environment.
These skeleton files provide default settings for profiles like .bashrc, .profile, desktop themes, and more. This gives the user a basic working environment once they login.
With useradd you would need to manually copy these defaults. For example:
# useradd joey
# mkdir /home/joey
# cp -r /etc/skel/. /home/joey
This ensures the user has default bash and profile configuration in their home folder to get started.
Conclusion
In summary, while useradd and adduser both allow creating users, adduser makes the process simpler by providing interactive prompts and handling home directory creation and skeleton files. This makes it the best choice in most cases.
However, useradd is more flexible for advanced use cases where automation and customization may be needed. It‘s also useful as a fallback if adduser is not installed.
When managing Linux users, keep these core differences in mind:
useradd– lower level, more customizationadduser– interactive, handles home directories and defaults
This will allow you to easily add users to your Linux system using the right tool for each situation.



