useradd Linux Command
Creates a new user account on the system.
What does useradd do?
Creates a new user account on the system.
Syntax
useradd [options] usernamePractical example
sudo useradd -m -s /bin/bash johnQuestions about useradd
How do I create a user with a home directory?
Use `sudo useradd -m username` to create a user with a home directory. The `-m` flag creates /home/username automatically.
How do I create a user with a specific shell?
Use `sudo useradd -s /bin/bash username` to set the login shell. Common shells are `/bin/bash`, `/bin/sh`, or `/bin/zsh`.
How do I create a user and set a password?
Create the user with `sudo useradd -m username`, then set a password with `sudo passwd username`.
How do I create a user in a specific group?
Use `sudo useradd -m -G groupname username` to add the user to a secondary group. Use `-g` for the primary group.
What is the difference between useradd and adduser?
`useradd` is the low-level command with fewer defaults. `adduser` is a friendlier wrapper that asks interactive questions and sets up more defaults.
How do I create a system user?
Use `sudo useradd -r -s /usr/sbin/nologin username` to create a system user for services. The `-r` flag assigns a UID in the system range.
How do I set an expiry date for a user account?
Use `sudo useradd -e 2025-12-31 username` to set an account expiration date. The account will be disabled after that date.
How do I see the default settings for useradd?
Use `useradd -D` to view and modify default settings like the default shell, home directory location, and password expiry.
Related User Management
passwdChanges the password for a user account.
usermodModifies an existing user account (groups, shell, home directory, etc.).
sudoExecutes a command with superuser (root) privileges.
userdelDeletes a user account. Use -r to also remove the home directory.
suSwitches to another user account or the root user.
groupaddCreates a new group on the system.