useradd is the low-level Linux command for creating local user accounts. It writes a new entry to the account databases, assigns a user ID (UID) and a primary group, and can create a home directory populated from a skeleton template. Because every file and process in Linux is owned by a user, useradd is where the permissions model of a system begins for each new identity.
The command belongs to the shadow-utils family of account tools and requires root privileges, normally obtained through sudo. It deliberately does little beyond what its options request, which makes it predictable in scripts but easy to misuse interactively.
What useradd changes on the system
When useradd runs, it updates several files under /etc in a single locked operation. The account record goes to /etc/passwd, the password hash entry goes to /etc/shadow, and group membership is written to /etc/group and /etc/gshadow. On many distributions it also allocates subordinate ID ranges for rootless containers.
The table below lists the files that a typical invocation touches and what each one stores.
| File | Content | Readable by |
|---|---|---|
| /etc/passwd | Name, UID, GID, comment, home, shell | All users |
| /etc/shadow | Password hash and aging fields | Root only |
| /etc/group | Group names, GIDs and members | All users |
| /etc/gshadow | Group passwords and administrators | Root only |
| /etc/subuid, /etc/subgid | Subordinate ID ranges | All users |
| Home directory | Copy of /etc/skel contents | The new user |
A newly created account is locked by default: the shadow entry contains a placeholder instead of a password hash, so nobody can log in with a password until an administrator runs passwd. This default is a deliberate safety measure, not an error.
Key useradd options
useradd behaves according to its command-line options and the defaults stored in configuration files. Explicit options always take precedence, which is why automation should state every value it depends on instead of trusting distribution defaults.
| Option | Effect | Example |
|---|---|---|
| -m | Create the home directory | useradd -m anna |
| -d | Set a custom home path | -d /srv/anna |
| -s | Set the login shell | -s /bin/bash |
| -u | Assign a specific UID | -u 1500 |
| -g | Set the primary group | -g developers |
| -G | Add supplementary groups | -G wheel,docker |
| -r | Create a system account | -r -s /usr/sbin/nologin svc |
| -e | Set an expiry date | -e 2027-06-30 |
| -c | Set the comment field | -c "Anna Novak" |
Defaults come from two sources. /etc/login.defs defines UID and GID ranges, password aging and whether home directories are created automatically, while /etc/default/useradd holds the default shell, home base and skeleton directory. Running useradd -D prints the effective defaults.
The home directory permissions depend on the HOME_MODE or UMASK setting in login.defs. Recent distributions usually create homes with mode 0700 or 0750, so other users cannot browse them, but older systems may still produce world-readable homes.
Regular users and system accounts
Linux distinguishes human accounts from system accounts by UID range. System accounts run services such as web servers or databases; they usually have no home in /home, no valid password and a non-login shell, which limits damage if the service is compromised.
| Account type | Typical UID range | Login shell | Purpose |
|---|---|---|---|
| Root account | 0 | /bin/bash | Full administrative control |
| System account | 1 to 999 | /usr/sbin/nologin | Running daemons and services |
| Regular user | 1000 and above | /bin/bash or similar | Interactive human logins |
| Nobody | 65534 | /usr/sbin/nologin | Unprivileged placeholder identity |
The exact boundaries are set by SYS_UID_MAX and UID_MIN in login.defs, and some older distributions start regular users at UID 500. Keeping UIDs consistent across servers matters whenever files are shared over NFS, because ownership is stored as a number, not a name.
useradd compared with adduser and related commands
useradd is the portable, scriptable baseline, but it is not the only way to create accounts. Debian and Ubuntu provide adduser, an interactive wrapper that prompts for a password and full name and applies friendlier defaults. Other commands in the same family modify or remove accounts after creation.
| Command | Role | Interactive |
|---|---|---|
| useradd | Create an account from options | No |
| adduser | Create an account with prompts (Debian family) | Yes |
| usermod | Change an existing account | No |
| userdel | Remove an account, optionally its home | No |
| passwd | Set or lock the password | Yes |
| groupadd | Create a new group | No |
On Red Hat family systems, adduser is merely a symbolic link to useradd, while on Debian it is a separate Perl program. Scripts that must run on both families should therefore call useradd directly with explicit options.
Pitfalls and security considerations
Most problems with useradd come from relying on implicit defaults. On Debian-based systems, for instance, useradd without -m creates no home directory and may assign /bin/sh as the shell, which surprises administrators used to adduser.
- Forgetting
-mleaves the user without a home directory, so the first login fails or lands in the root directory. - Using
usermod -Glater without-areplaces all supplementary groups instead of appending to them. - Adding a user to wheel, sudo or docker grants near-root power and should be a deliberate, reviewed decision.
- Passing a password hash with
-pexposes it in the process list and shell history; setting it afterward with passwd or chpasswd is safer. - Reusing a UID that once belonged to a deleted user lets the new account inherit old files that still carry that number.
In larger environments, local accounts are often replaced by central identity services such as LDAP or FreeIPA, or managed through configuration tools. useradd remains essential for service accounts, recovery access and container images, where a small, predictable local identity is exactly what is needed.
Stripped to the essentials
useradd is how a Linux computer gets a new member of the household. It writes the person’s name into the list of residents, gives them a personal number, assigns them to groups and can prepare an empty room for their belongings.
What it does not do is hand over a key. The new account cannot log in with a password until an administrator sets one, which prevents a half-finished account from becoming an open door.
Where it is applied
A hosting team prepares a server for a new web application. Instead of running the application as root, the administrator creates a dedicated identity with useradd -r -s /usr/sbin/nologin -d /srv/shop -M shopapp, then gives that account ownership of /srv/shop with chown.
Later the same week, a new developer joins. The administrator runs useradd -m -s /bin/bash -G developers -c "Petra Kovac" petra, sets an initial password with passwd, and forces a change at first login with passwd -e petra. The developer can read the shared project directory through the group, but has no sudo rights.
When a vulnerability in the web application is later exploited, the attacker gains only the unprivileged shopapp account, which has no shell and no access to other users’ files. The damage stays confined to one directory, and the investigation takes hours instead of days.