Skip to content

useradd Command Cheat Sheet

useradd is a low-level utility for creating users. On Debian/Ubuntu, adduser (a Perl script) is often recommended for interactive ease, but useradd is the standard cross-distro tool.


Synopsis

useradd [options] LOGIN

Best Practice Example

Create a user with a home directory, specific shell, and comment (Full Name).

# -m: Create home directory
# -s: Login shell
# -c: Comment (Full Name)
sudo useradd -m -s /bin/bash -c "John Doe" john

Essential Options

Create Home Directory (-m)

By default, useradd might not create /home/john. Always use -m for normal users.

sudo useradd -m john

Specify Shell (-s)

Default is often /bin/sh. For a modern experience:

sudo useradd -s /bin/bash john

Add to Groups (-G)

Add to additional groups (comma-separated).

# Add to 'sudo' (admin) and 'docker' groups
sudo useradd -m -G sudo,docker john

System User (-r)

Create a system account (no home dir, low UID).

sudo useradd -r -s /usr/sbin/nologin nginx

Password Management

useradd creates the user in a locked state (no password). You must set it immediately.

sudo passwd john

Or set it non-interactively (scripting):

echo "john:password123" | sudo chpasswd

Defaults

Defaults are stored in /etc/default/useradd. View them:

useradd -D
  • SKEL: /etc/skel (Template directory copied to new users' homes).