Adding a User
useradd Command
The useradd command is used to add a new user to EulerOS.
Table 3-1 describes common useradd command options.
Option |
Description |
---|---|
-c comment |
User's password file comment. |
-d home dir |
User's login directory. The default directory is /home/account name. |
-e expire_date |
Date (MM/DD/YY) on which the user's account will expire. |
-f inactive_days |
Number of days after the user's account expires until it is permanently disabled. If this option takes the value 0, the account is disabled immediately after it expires. If this option takes the value -1, the account is not be disabled after it expires. |
-g initial_group |
Group name or group number of the user's initial group. |
-G |
List of supplementary groups of the new account. |
-M |
Create the home directory automatically if it does not exist. |
-n |
Cancel the default settings in which the user group name is the same as the user name. |
-r |
Create a system account with a UID less than 500 and without a home directory. NOTE:
Use the -m option if you want to create a system account with a home directory. |
-s shell |
User's login shell. |
-u uid |
User ID of the user, which must be greater than 99. This value must be unique, unless the -o option is used. The value must be non-negative. Values 0–99 are reserved for system accounts and should not be assigned to users. |
-D |
Default useradd command option settings are displayed. |
User Information Files
The following files contain user account information:
- /etc/passwd: user account information
- /etc/shadow file: user account encryption information
- /etc/group file: group information
- /etc/default/useradd: default configurations
- /etc/login.defs: system wide settings
- /etc/skel: default directory that holds initial configuration files
Example
To create a user XXX, run the following command:
[root@localhost ~]# useradd XXX
If no prompt is displayed, the user XXX is successfully created. After the user XXX is created, run the passwd command to assign a password to the user. A new account without a password will be banned.
To view information about the new user, run the id command:
[root@localhost ~]# id user_example uid=502(user_example) gid=502(user_example)
To change the password of the user_example, run the following command:
[root@localhost ~]# passwd user_example
Then, type the password and confirm it as prompted:
Changing password for user user_example. New password: BAD PASSWORD:it is based on a dictionary word Retype new password: passwd:all authentication tokens updated successfully.