Cybersecurity Updates & Tools

How to Create Users in Linux with useradd: A Complete Guide

Linux is a multi-user system. Each person or service that needs access should have its own dedicated account with separate permissions, a home directory, and its own group membership.

useradd is the command-line tool for creating new user accounts. Only root or users with sudo privileges can run it.

How to Create Users in Linux with useradd

The syntax is:

bashuseradd [OPTIONS] USERNAME

To create a basic account:

bashsudo useradd leah

This adds entries to four files: /etc/passwd/etc/shadow/etc/group, and /etc/gshadow. The account exists immediately but is locked the user cannot log in until a password is set.

Set a password right away:

bashsudo passwd leah

Without this step, the account is inaccessible.

Create a home directory. On many distributions, useradd without options does not create a home directory. Always pass -m to create it:

bashsudo useradd -m leah

This creates /home/leah and copies default dotfiles from /etc/skel — including .bashrc.bash_logout, and .profile — into the new directory. Skipping -m is the most common source of confusion after account creation.

To place the home directory at a different path, combine -m with -d:

bashsudo useradd -m -d /opt/leah leah

Verify the account with id:

bashid leah

useradd reads settings from two files. /etc/default/useradd controls the default shell, the /etc/skel path, and the home directory prefix. /etc/login.defs controls UID ranges and password aging policy. To view current defaults:

bashuseradd -Dsudo useradd -D -s /bin/bash    # change default shell for future accounts

Customize Users: Groups, Shell, UID, and Comment

Set a specific UID with -u. By default, the system assigns the next available UID from the range in /etc/login.defs:

bashsudo useradd -u 1500 leah

Groups. Each user has exactly one primary group and can belong to zero or more supplementary groups.

  • -g GROUP — set the primary login group; the group must already exist
  • -G group1,group2 — add the user to supplementary groups; all must already exist
bashsudo useradd -g users -G wheel,docker zoe

Without -guseradd creates a new group with the same name and GID as the user. If you use -g or -G, create the group first with groupadd if it does not exist.

Set the login shell with -s. The default comes from /etc/default/useradd and varies by distribution:

bashsudo useradd -s /usr/bin/zsh zoe

Add a comment with -c. This populates the GECOS field in /etc/passwd, typically used for the user’s full name:

bashsudo useradd -c "Test User Account" zoe

System Users, Expiry Dates, and useradd vs adduser

Temporary accounts use -e to set an expiry date in YYYY-MM-DD format:

bashsudo useradd -e 2027-01-22 zoe

Check the expiry with sudo chage -l zoe.

System users are for services, not people. Use -r to create one. System accounts get a UID from the lower system user range defined in /etc/login.defs, have no expiry by default, and should be given no interactive login shell:

bashsudo useradd -r -s /usr/sbin/nologin myappuser

This is the correct pattern for service accounts: the process runs under a dedicated user but that user cannot log in interactively.

useradd vs adduser. On Debian-based systems like Ubuntu, adduser is a higher-level interactive script that calls useradd internally. It automatically creates the home directory, prompts for a password, and handles most common setup steps. useradd is the low-level binary available on every Linux distribution and is the right choice for scripts and automation.

Create accounts with sudo useradd -m username, then immediately run sudo passwd username. Use -G for supplementary group membership, -s for the login shell, and -r -s /usr/sbin/nologin for service accounts that must not allow interactive login. Leave a comment below if you run into any issues.