useradd

On this page 7

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.

FileContentReadable by
/etc/passwdName, UID, GID, comment, home, shellAll users
/etc/shadowPassword hash and aging fieldsRoot only
/etc/groupGroup names, GIDs and membersAll users
/etc/gshadowGroup passwords and administratorsRoot only
/etc/subuid, /etc/subgidSubordinate ID rangesAll users
Home directoryCopy of /etc/skel contentsThe new user
Files modified by useradd

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.

OptionEffectExample
-mCreate the home directoryuseradd -m anna
-dSet a custom home path-d /srv/anna
-sSet the login shell-s /bin/bash
-uAssign a specific UID-u 1500
-gSet the primary group-g developers
-GAdd supplementary groups-G wheel,docker
-rCreate a system account-r -s /usr/sbin/nologin svc
-eSet an expiry date-e 2027-06-30
-cSet the comment field-c "Anna Novak"
Commonly used options

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 typeTypical UID rangeLogin shellPurpose
Root account0/bin/bashFull administrative control
System account1 to 999/usr/sbin/nologinRunning daemons and services
Regular user1000 and above/bin/bash or similarInteractive human logins
Nobody65534/usr/sbin/nologinUnprivileged placeholder identity
Typical account types

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 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.

CommandRoleInteractive
useraddCreate an account from optionsNo
adduserCreate an account with prompts (Debian family)Yes
usermodChange an existing accountNo
userdelRemove an account, optionally its homeNo
passwdSet or lock the passwordYes
groupaddCreate a new groupNo
Account management commands

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 -m leaves the user without a home directory, so the first login fails or lands in the root directory.
  • Using usermod -G later without -a replaces 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 -p exposes 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.