Difference between useradd and adduser in Linux System
1. Purpose
In this post, I will explain the key difference between the useradd
and adduser
commands in Linux Operating Systems.
2. Environment
- Ubuntu System
3. What is the difference between the useradd
and adduser
in Linux?
3.1 What is useradd
?
The Linux useradd
command is used to create user accounts. With useradd
, you can establish new user accounts. After creating an account, you can set its password using the passwd
command. Additionally, the userdel
command can be used to delete user accounts.
Just as the following diagram shows:
You can see that the useradd
command is atomic, you must manually call the passwd
command to set user’s password after the account creation.
The syntax of the useradd
command is:
useradd [options] username
The most frequently used options of useradd
are:
-c, --comment
: Add a comment/description for the user.-d, --home
: Specify the user’s home directory.-g, --gid
: Specify the user’s initial group.-G, --groups
: Specify the user’s supplementary groups.-m, --create-home
: Create the user’s home directory during user creation.-s, --shell
: Specify the user’s login shell.-u, --uid
: Specify the user’s user ID.
for example, if you want to create a user named john
, you can just type:
useradd john
however, you should know that the above command does NOT create home directory and password for john
, you must type:
passwd john
to set his password manually.
After the account creation, you can see /etc/passwd
to check its status:
root@launch-advisor-20141217:~# cat /etc/passwd|grep johnjohn:x:1000:1000::/home/john:/bin/sh
you can see that john
’s shell is not /bin/bash
, which is more sophisticated,
3.2 What is adduser
?
The adduser
command is typically a Perl script that serves as a higher-level wrapper, providing a more user-friendly interactive frontend for useradd
. It may exhibit some differences across various Linux distributions, particularly between the Debian/Ubuntu and Red Hat/CentOS families. On Debian/Ubuntu systems, adduser
offers more extensive functionality and stronger interactivity. In some Red Hat-based distributions, adduser
might simply be a symbolic link to useradd.
Here is a diagram shows adduser
is more interactive and more advanced command than useradd
:
Here is an example of using adduser
:
Adding user `john' ...Adding new group `john' (1000) ...Adding new user `john' (1000) with group `john' ...Creating home directory `/home/john' ...Copying files from `/etc/skel' ...New password:Retype new password:passwd: password updated successfullyChanging the user information for johnEnter the new value, or press ENTER for the default Full Name []: john Room Number []: 11 Work Phone []: 1 Home Phone []: 1 Other []: 1Is the information correct? [Y/n] Yroot@launch-advisor-20141217:~#
You can see that when executing adduser username
, the script will sequentially complete a full process including password setting
, user information collection
, home directory construction
, and environment configuration
, significantly reducing the complexity of manual operations. The interactive process includes prompts such as password confirmation and full name input, enabling junior administrators to complete account configuration quickly.
To summarize:
The adduser
will successively prompt for the following inputs:
-
- Password and password confirmation
-
- User’s full name
-
- Information such as contact details (optional)
And User group handling: adduser
will create a user group with the same name by default.
3.3 The difference
Feature | useradd | adduser |
---|---|---|
Type | Low-level binary tool | High-level script (usually a Perl script) |
Interactivity | Non-interactive (requires options) | Usually interactive (provides prompts) |
Home Directory | Not created by default (requires -m option) | Created by default |
Password Setup | Not set by default (requires passwd) | Usually prompted during creation |
Default Config | Depends on /etc/default/useradd file | Depends on /etc/adduser.conf file (on Debian/Ubuntu etc.) |
Portability | Good (common across distributions) | May vary depending on distribution |
Use Case | Script automation, precise control over user attributes | Manual user creation, new administrators, quick standard user creation |
4. Summary
In this post, I explained the differences between the useradd
and adduser
commands in Linux. While both commands are used to create user accounts, adduser
offers more advanced interactivity and automation compared to useradd
. Understanding these differences can help you choose the right tool for managing user accounts on your Linux system.
Final Words + More Resources
My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!