HxHippy

useradd

Create a new user or update default new user information

Overview

The useradd command creates a new user account or updates default new user information from the command line.

Syntax

useradd [options] LOGIN

Common Options

-c comment, --comment comment

Any text string. It is generally a short description of the login, and is currently used as the field for the user's full name.

-d home_dir, --home home_dir

The new user will be created using home_dir as the value for the user's login directory.

-e expire_date, --expiredate expire_date

The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD.

-g initial_group, --gid initial_group

The group name or number of the user's initial login group.

-G group,[,...], --groups group,[,...]

A list of supplementary groups which the user is also a member of.

-m, --create-home

Create the user's home directory if it does not exist.

-M, --no-create-home

Do not create the user's home directory.

-s shell, --shell shell

The name of the user's login shell.

-u uid, --uid uid

The numerical value of the user's ID. This value must be unique, unless the -o option is used.

-p password, --password password

The encrypted password, as returned by crypt(3). Use with caution, as the password is visible on the command line.

-r, --system

Create a system account.

Examples

$ sudo useradd newuser

Creates a new user named newuser with default settings.

$ sudo useradd -m -d /home/jdoe -s /bin/bash -c "John Doe" jdoe

Creates user jdoe with a home directory, bash shell, and full name comment.

$ sudo useradd -G developers,testers -e 2024-12-31 tempworker

Creates tempworker, adds them to developers and testers groups, with an account expiry date.

$ sudo useradd -r -s /sbin/nologin appuser

Creates a system user appuser with no login shell.

$ sudo useradd -u 1001 specificid_user

Creates a user with a specific UID 1001.

useraccountcreateaddnew useruseradd