What Is the Linux useradd Command Used For?
The useradd command is a foundational command-line
utility in Linux used by system administrators to create and configure
new user accounts. This article explains the primary function of
useradd, outlines its most common command-line flags,
contrasts it with higher-level alternatives, and demonstrates how it
integrates with system files to establish user environments
securely.
Core Function of useradd
In Linux administration, useradd is a low-level native
utility that adds user entries to the system. When executed with
administrative privileges (typically via sudo),
useradd performs the backend tasks required to register a
new identity:
- It records the account information in
/etc/passwd. - It creates a corresponding entry for encrypted password metadata in
/etc/shadow. - It defines the user's primary group in
/etc/group.
Because useradd is a low-level tool, it does not prompt
for information interactively. By default on many distributions, running
useradd username creates the user in an inactive state
without a password, a dedicated home directory, or a custom login shell
unless specific flags or system defaults are provided.
Common Options and Usage
To build a fully functional user account, administrators combine
useradd with various flags:
-m(Create Home Directory): Generates the user's home directory (usually/home/username) and populates it with default configuration files from/etc/skel.-s(Specify Login Shell): Sets the user's default command-line shell, such as/bin/bashor/usr/bin/zsh.-g(Primary Group): Assigns an existing primary group to the user by name or GID.-G(Supplementary Groups): Adds the user to secondary groups (e.g.,sudo,docker) as a comma-separated list.-u(User ID): Manually assigns a specific numeric User ID (UID).-e(Expiration Date): Defines a date (inYYYY-MM-DDformat) on which the user account automatically expires and locks.
A standard administrative command to create a complete user account looks like this:
sudo useradd -m -s /bin/bash -G wheel,developers developer1Finalizing Account Creation
After creating an account with useradd, the account
remains locked until a password is set. Administrators must pair
useradd with the passwd command:
sudo passwd developer1This step sets the authentication secret in /etc/shadow,
enabling the user to log in via console or SSH.
useradd vs. adduser
While useradd is a universal binary standard across
virtually all Linux distributions (including RHEL, CentOS, Arch, and
Debian), many Debian-based distributions also include
adduser. Unlike useradd, adduser
is a high-level Perl script that guides the administrator through an
interactive prompt, automatically creates a home directory, and sets
passwords in a single workflow. However, useradd remains
the industry standard for automation scripts, configuration management
tools, and headless server provisioning.