System Management Commands USERADD(8) linux

useradd - create a new user or update default new user information

useradd -D

useradd [options] loginName

Creates a new user account using the values specified on the command line and the default values from the system. May create the new user's home directory and copy initial files there.
Some versions will create a group for each user added to the system by default.

Suggested usage:
sudo adduser --comment "firstname lastname" --create-home flastname
sudo passwd flastname

-u
--uid uid
Numerical uid, unsigned, and unique, (unless the -o is used).
Default uses the next higher number than currently exists.
0 - 999 are typically reserved for system accounts.
-o
--non-unique
Allow the creation of a user with a non-unique uid, a synonum.
-g
--gid group
group name or number for the user's initial group, refering to an existing group.
-G
-groups g1[,g2,…[,gn]]]
list of supplementary groups of which the user is also a member, separated by commas, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g.
No default.
-n This option turns off the Red Hat Linux specific behavior to create group having the same name as the user being added . When this option is used, users by default will be placed in whatever group is specified in /etc/default/useradd.
If no default group is defined, group 1 will be used.
-c
--comment comment
generally a short description of the login, and is used as the field for the user's full name.
 
-m
--create-home

-k
--skel skel_dir

Create home directory.
Files contained in /etc/skel will be copied there.
-k overrides /etc/skel.
Directories in /etc/skel or skel_dir will be created in the user's home directory .
(The -k is only valid in conjunction with -m . )
Default does not create the directory and does not copy files.
-b
--base-dir base_dir
default base directory for the system if -d dir is not specified. base_dir is concatenated with the account name to define the home directory.
If -m is not used, base_dir must exist.
-d
--home home_dir
New user's login directory, will not be created.
Default concatonates base_dir and login
-M The user's home directory will not be created.
 
-p
--password password
The encrypted password, as returned by crypt.
The default is to have the account disabled. Since it is nearly impossible to correctly enter the crypted password, my advise is to leave the account disabled, then enter the password using sudo passwd loginName
-e
--expiredate yyyy-mm-dd
date the account will be disabled,
-f
--inactive days
grace period, in days, after a password expires, after which the account is disabled.
0 disables the account as soon as the password has expired, and
-1 disables password ageing.
The default value is -1.
-K
--key KEY=VALUE
Overrides /etc/login.defs defaults (UID_MIN, UID_MAX, UMASK, PASS_MAX_DAYS and others).
Example: -K PASS_MAX_DAYS=-1 can be used when creating system account to turn off password ageing, even though system account has no password at all.
Multiple -K entries can be specified, e.g.: -K UID_MIN=100 -K UID_MAX=499
-r This flag is used to create a system account. That is, a user with a UID lower than the value of UID_MIN defined in /etc/login.defs and whose password does not expire no a home directory is created unless -m is present. This is an option added by Red Hat
-s
--shell SHELL
login shell. The default leaves this field blank, which causes the system to select the default login shell.
-l lower case L Do not add the user to the last login log file.
-Z
--selinux-user SEUSER
The SELinux user for the user's login. The default is to leave this field blank, which causes the system to select the default SELinux user.
-h
--help
Display help message and exit.


When invoked with -D either display the current default values, or update the default values from the command line.
-b home_dir initial path prefix for a new user's home directory. The user's name will be affixed to the end of home_dir to create the new directory name if the -d is not used when creating a new account.
-e expire_date date on which the user account is disabled.
-f days number of days after a password has expired before the account will be disabled.
-g
--gid group
group name or ID for a new user's initial group, must exist, and a numerical group ID must have an existing entry.
-s
--shell shell
name of the new user's login shell to be used for all future new user accounts.

If no options are specified, useradd displays the current default values.

The system administrator is responsible for placing the default user files in /etc/skel .

CAVEATS
Adding a user to a NIS group must be performed on the NIS server.

if the username already exists in an external user database such as NIS, useradd will deny the user account creation request.

FILES

/etc/passwd User account information.
/etc/shadow Secure user account information.
/etc/group Group account information.
/etc/gshadow Secure group account information.
/etc/default/useradd Default values for account creation.
/etc/skel/ Directory containing default files.
/etc/login.defs Shadow password suite configuration.

EXIT VALUES

0 success
1 can't update password file
2 invalid command syntax
3 invalid argument to option
4 UID already in use (and no -o)
6 specified group doesn't exist
9 username already in use
10 can't update group file
12 can't create home directory
13 can't create mail spool

See userdel, usermod, chfn, chsh, passwd, crypt, groupadd, groupdel, groupmod, login.defs,

System Management Commands 06/24/2006 USERADD(8)