🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

useradd Command

Intermediate User Management man(1)

Create a new user account

👁 14 views 📅 Updated: Mar 15, 2026
SYNTAX
useradd [OPTION]... USERNAME

What Does useradd Do?

useradd creates a new user account on the system. It is a low-level command that creates the user entry in /etc/passwd and /etc/shadow, optionally creating a home directory and setting initial configuration.

useradd requires root privileges. It creates the user but does not set a password — use passwd after useradd to set one. The adduser command (on Debian/Ubuntu) is an interactive wrapper that is easier to use.

useradd is preferred in scripts because of its non-interactive nature and consistent behavior across distributions.

Options & Flags

OptionDescriptionExample
-m Create home directory useradd -m newuser
-d Specify home directory path useradd -m -d /home/custom newuser
-s Set login shell useradd -m -s /bin/bash newuser
-g Set primary group useradd -g developers newuser
-G Set additional groups useradd -G sudo,docker newuser
-c Set comment (full name) useradd -c 'John Doe' jdoe
-e Set account expiration date useradd -e 2025-12-31 tempuser
-r Create system account (no home, low UID) useradd -r -s /sbin/nologin appuser
-u Specify UID useradd -u 1500 newuser

Practical Examples

#1 Create user with home

Creates a user with home directory, bash shell, and full name.
$ sudo useradd -m -s /bin/bash -c "John Doe" jdoe

#2 Set password

Sets password for the new user (always do this after useradd).
$ sudo passwd jdoe

#3 Create with groups

Creates a user in the sudo and docker groups.
$ sudo useradd -m -s /bin/bash -G sudo,docker developer

#4 Create system account

Creates a service account that cannot login interactively.
$ sudo useradd -r -s /sbin/nologin -d /var/lib/myapp myapp

#5 Create temporary user

Creates a user account that expires on a specific date.
$ sudo useradd -m -e 2025-06-30 contractor

#6 Full user creation script

Complete user creation with home directory, shell, name, sudo access, and password.
$ sudo useradd -m -s /bin/bash -c "Jane Smith" -G sudo jsmith && sudo passwd jsmith

Tips & Best Practices

Always set a password: useradd does NOT set a password. The account is locked until you run: sudo passwd username.
Use adduser on Debian/Ubuntu: adduser is an interactive wrapper that creates home directory, prompts for password, and sets up the account in one step.
-m is not always default: On RHEL/CentOS, -m creates the home directory. On Debian/Ubuntu, it may be the default. Always use -m to be safe.

Frequently Asked Questions

How do I create a new user?
sudo useradd -m -s /bin/bash username && sudo passwd username. The -m creates home directory, -s sets the shell.
How do I create a service account?
sudo useradd -r -s /sbin/nologin service_name. The -r flag creates a system account with a low UID and no home directory.
What is the difference between useradd and adduser?
useradd is the low-level command. adduser (Debian/Ubuntu) is a friendly wrapper that prompts interactively. Use useradd in scripts.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →