Glossary

useradd

useradd creates a new user account. It is the low-level, scriptable interface; the more user-friendly adduser is a Debian-specific Perl wrapper that prompts for details, creates the home directory, copies skeleton files, and sets a password.

sudo useradd -m -s /bin/bash alice         # create with home and shell
sudo useradd -r -s /usr/sbin/nologin www   # system account, no shell
sudo useradd -G docker,wheel alice         # supplementary groups
sudo useradd -u 1234 -g 1234 special       # explicit UID/GID
sudo passwd alice                           # set initial password

Without -m, useradd does not create the home directory. Without explicit shell and password, the account is unusable for interactive login—which is sometimes exactly what you want for a service account. Defaults come from /etc/default/useradd and /etc/login.defs, which set things like whether /home/<user> is created, which skeleton files are copied from /etc/skel, and which UID range to pick from.

Sister commands include usermod (modify an existing account), userdel (remove one, optionally with home directory via -r), passwd (change password), and chage (change password-aging parameters). Together they are the primary way to script user management; behind the scenes they all modify /etc/passwd, /etc/shadow, and /etc/group.

Related terms: /etc/passwd

Discussed in:

Also defined in: Textbook of Linux