useradd
user managementLinux/Unix
The useradd command is one of the most frequently used commands in Linux/Unix-like operating systems. useradd Create a new user or update default new user information
Quick Reference
Command Name:
useradd
Category:
user management
Platform:
Linux/Unix
Basic Usage:
useradd [options] [arguments]
Common Use Cases
Syntax
useradd [options] LOGIN
Options
Option | Description |
---|---|
-b, --base-dir BASE_DIR |
Base directory for the home directory of the new account |
-c, --comment COMMENT |
GECOS field of the new account |
-d, --home-dir HOME_DIR |
Home directory of the new account |
-D, --defaults |
Print or change default useradd configuration |
-e, --expiredate EXPIRE_DATE |
Expiration date of the new account (YYYY-MM-DD) |
-f, --inactive INACTIVE |
Password inactivity period of the new account |
-g, --gid GROUP |
Name or ID of the primary group of the new account |
-G, --groups GROUPS |
List of supplementary groups of the new account |
-h, --help |
Display help message and exit |
-k, --skel SKEL_DIR |
Use this alternative skeleton directory |
-K, --key KEY=VALUE |
Override /etc/login.defs defaults |
-l, --no-log-init |
Do not add the user to the lastlog and faillog databases |
-m, --create-home |
Create the user's home directory |
-M, --no-create-home |
Do not create the user's home directory |
-N, --no-user-group |
Do not create a group with the same name as the user |
-o, --non-unique |
Allow to create users with duplicate (non-unique) UID |
-p, --password PASSWORD |
Encrypted password of the new account |
-r, --system |
Create a system account |
-s, --shell SHELL |
Login shell of the new account |
-u, --uid UID |
User ID of the new account |
-U, --user-group |
Create a group with the same name as the user |
-Z, --selinux-user SEUSER |
Use a specific SEUSER for the SELinux user mapping |
Examples
How to Use These Examples
The examples below show common ways to use the useradd
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
# Create a new user with default settings
sudo useradd johndoe