Quick take: Use sudo useradd -m -s /bin/bash username to create a user with a home directory and shell, then sudo passwd username to set a password. On Debian/Ubuntu, the friendlier adduser does it all interactively.
Introduction
Creating user accounts is a core administration task, and Linux offers two tools: the low-level useradd (available everywhere) and the friendlier adduser (a Debian/Ubuntu wrapper that prompts you through the process). Knowing both lets you create users interactively or script account creation in bulk.
This guide covers creating users with the right home directory, shell, and groups, making system accounts, and choosing between useradd and adduser.
Syntax
The basic syntax of the useradd command is:
useradd [OPTIONS] USERNAMECommon Options and Parameters
The most useful options and parameters for the useradd command:
| Option | Description |
|---|---|
| -m | Create the user's home directory. |
| -s SHELL | Set the login shell (e.g. /bin/bash). |
| -G groups | Add the user to supplementary groups (comma-separated). |
| -g group | Set the primary group. |
| -d DIR | Set a custom home directory path. |
| -r | Create a system account (no aging, low UID). |
| -e DATE | Set an account expiry date. |
| -c 'TEXT' | Set the comment/full-name field. |
Practical Examples
Real useradd commands you can run today:
# Create a user with home directory and bash shell
sudo useradd -m -s /bin/bash alice
# Set the new user's password
sudo passwd alice
# Create a user and add to the sudo and docker groups
sudo useradd -m -G sudo,docker alice
# Create a system account for a service
sudo useradd -r -s /usr/sbin/nologin appsvc
# Friendlier interactive creation (Debian/Ubuntu)
sudo adduser alice
# Delete a user and their home directory
sudo userdel -r aliceTips and Best Practices
- Always pass
-mwith useradd, or the user will have no home directory until you create one manually. - On Ubuntu,
adduseris usually the better choice — it creates the home directory, sets the shell, and prompts for a password automatically. - For service accounts use
-rand a nologin shell so the account cannot be used to log in interactively.
Final Thoughts
Creating users comes down to two tools: useradd for precise, scriptable control and adduser for an easy interactive flow on Debian-based systems. Remember -m for the home directory, -s for the shell, and -G for group membership, then set a password with passwd. For service accounts, lock them down with -r and a nologin shell.
FAQ: useradd Command in Linux
What is the difference between useradd and adduser?+
useradd is the low-level command available on all Linux systems and needs explicit options. adduser is a friendlier Perl wrapper on Debian and Ubuntu that interactively creates the home directory, sets the shell, and prompts for a password.
How do I create a user with a home directory?+
Use the -m flag: sudo useradd -m -s /bin/bash username creates the home directory and sets bash as the shell. Then set a password with sudo passwd username.
How do I add a user to a group when creating them?+
Use -G with a comma-separated list: sudo useradd -m -G sudo,docker username adds the user to those supplementary groups at creation time.
How do I create a system user for a service?+
Use -r and a nologin shell: sudo useradd -r -s /usr/sbin/nologin appsvc creates a service account that cannot log in interactively.
How do I delete a user in Linux?+
Use userdel: sudo userdel username removes the account, and sudo userdel -r username also deletes their home directory and mail spool.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support