33.2.2. Adding a User

33.2.2. Adding a User

To add a user to the system:

  1. Issue the useradd command to create a locked user account:

    useradd <username>
  2. Unlock the account by issuing the passwd command to assign a password and set password aging guidelines:

    passwd <username>

Command line options for useradd are detailed in Table 33.1, “useradd Command Line Options”.

Option Description
-c '<comment>' <comment> can be replaced with any string. This option is generally used to specify the full name of a user.
-d<home-dir> Home directory to be used instead of default /home/<username>/
-e<date> Date for the account to be disabled in the format YYYY-MM-DD
-f<days> Number of days after the password expires until the account is disabled. If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not be disabled after the password expires.
-g<group-name> Group name or group number for the user's default group. The group must exist prior to being specified here.
-G<group-list> List of additional (other than default) group names or group numbers, separated by commas, of which the user is a member. The groups must exist prior to being specified here.
-m Create the home directory if it does not exist.
-M Do not create the home directory.
-n Do not create a user private group for the user.
-r Create a system account with a UID less than 500 and without a home directory
-p<password> The password encrypted with crypt
-s User's login shell, which defaults to /bin/bash
-u<uid> User ID for the user, which must be unique and greater than 499

Table 33.1. useradd Command Line Options

Note: This documentation is provided {and copyrighted} by Red Hat®, Inc. and is released via the Open Publication License. The copyright holder has added the further requirement that Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. The CentOS project redistributes these original works (in their unmodified form) as a reference for CentOS-5 because CentOS-5 is built from publicly available, open source SRPMS. The documentation is unmodified to be compliant with upstream distribution policy. Neither CentOS-5 nor the CentOS Project are in any way affiliated with or sponsored by Red Hat®, Inc.