Search notes:

Shell command useradd: create new user or update default new user information

useradd creates a new user or updates default new user information.
It is a low level utility. Therefore, you might want to use adduser.
$ useradd -s /bin/bash -m  rene
-s specifies the default shell for the new user. If not specified, it takes the value of SHELL variable in /etc/default/useradd.
-m creates the new user's home directory if it does not exist.

command line options

$ useradd ---help
useradd [options] LOGIN
useradd -D
useradd -D [options]
--badnames Do not check for bad names
-b --base-dir BASE_DIR Base directory for the home directory of the new account
--btrfs-subvolume-home Use BTRFS subvolume for home directory
-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
-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 this 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
-R --root CHROOT_DIR Directory to chroot into
-P --prefix PREFIX_DIR Prefix directory where are located the /etc/* files
-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

Adding a user to a group (for example sudo)

usermod can be used to add an already created user to an already created group:
$ usermod -a -G sudo rene
Make sure that /etc/sudoers is configured to allow users in the sudo group to execute sudo commands.

Populating the users home directory (-k)

By default, the home directory of a new user is populated with the files from the SKEL variable in /etc/default/useradd (default: /etc/skel/*).
This directory can be overwritten with -k /path/to/directory.
In order to not create any files in the home directory, use -k /dev/null.

Not adding the user to the faillog and lastlog databases (-l)

When -l is specified, the user is not added to the faillog and lastlog databases.

Changing the users password

After creating a user, the password for the user might be set with passwd
useradd -m rene
passwd rene

Defaults

Some defaults (such as if a Home directory should be created) are configured in /etc/login.defs

See also

A user is removed/deleted with userdel and modified with usermod.
Shell commands such as groupadd and passwd.

Index