useradd
Commanduseradd
The useradd
command is used to create a new user account on a Linux system. It is typically run with superuser privileges and allows administrators to specify various options to configure the new user's account settings.
useradd [OPTIONS] USERNAME
useradd
The useradd
command supports a variety of options:
-d, --home
- Specify the home directory for the new user. Default is /home/USERNAME
.-m, --create-home
- Create the user's home directory if it does not exist.-s, --shell
- Specify the user's login shell. Default is usually /bin/bash
.-G, --groups
- Specify a comma-separated list of supplementary groups for the user.-u, --uid
- Specify a numerical user ID for the new user.-g, --gid
- Specify the primary group for the new user.-p, --password
- Set the user's password (encrypted).-e, --expiredate
- Set an expiration date for the user's account.-f, --inactive
- Set the number of days after a password expires until the account is disabled.-r, --system
- Create a system account.-h, --help
- Display help information and exit.useradd
Commandsudo useradd newuser
This command creates a new user named newuser
with default settings.
sudo useradd -m newuser
This command creates a new user newuser
and also creates a home directory at /home/newuser
.
sudo useradd -s /bin/zsh newuser
This command creates a new user newuser
with the Zsh shell as the login shell.
sudo useradd -g developers newuser
This command creates newuser
and assigns them to the developers
primary group.
sudo useradd -e 2025-12-31 newuser
This command creates newuser
and sets their account to expire on December 31, 2025.
When a user is created using the useradd
command:
/etc/passwd
file.Option | Description |
---|---|
-d, --home |
Specify the home directory for the new user. Default is /home/USERNAME . |
-m, --create-home |
Create the user's home directory if it does not exist. |
-s, --shell |
Specify the user's login shell. Default is usually /bin/bash . |
-G, --groups |
Specify a comma-separated list of supplementary groups for the user. |
-u, --uid |
Specify a numerical user ID for the new user. |
-g, --gid |
Specify the primary group for the new user. |
-p, --password |
Set the user's password (encrypted). |
-e, --expiredate |
Set an expiration date for the user's account. |
-f, --inactive |
Set the number of days after a password expires until the account is disabled. |
-r, --system |
Create a system account. |
-h, --help |
Display help information and exit. |