useradd
1. Purpose
The useradd command is used to create user accounts and create the user’s home directory, with superuser privileges required.
2. Format
useradd [-d home] [-s shell] [-c comment] [-m [-k template]] [-f inactive] [-e expire] [-p passwd] [-r] name
3. Main Parameters
-c: Adds a comment text, which is saved in the comment field of passwd.
-d: Specifies the home directory the user logs into.
-D: Changes default values.
-e: Specifies the account expiration date; default means permanently valid.
-f: Specifies the number of days after password expiration before the account is disabled.
-g: Specifies the primary group the user belongs to.
-G: Specifies supplementary groups the user belongs to.
-m [-k] : Forces creation of the user home directory. (The user home directory will be created if it does not exist. If the -k option is used, files contained in skeleton_dir will be copied to the home directory, without copying files from /etc/skel. If the -k option is not used, files under /etc/skel will be copied to the user home directory. The -k option only applies when used together with the -m option. By default, the directory is not created and no files are copied.)
-M: Do not automatically create the user’s login directory.
-n: Cancel creating a group named after the username.
-r: Create a system account.
-s: Specifies the shell to be used after the user logs in.
-u: Specifies the user ID number.
4. Description
useradd can be used to create user accounts; it is identical to the adduser command. After the account is created, use passwd to set the account password. Accounts created using the useradd command are actually stored in the /etc/passwd text file.
usermod
1. Purpose
Modify user accounts.
2. Format
usermod [-c comment] [-d home_dir [-m]] [-e expire_date] [-f inactive_time] [-g initial_group] [-G group [,…]] [-l login_name][-p passwd] [-s shell] [-u uid [-o]] [-L|-U] login
3. Main Parameters
-c
-d
-e
-f
-g
-G
-l
-L: Locks the user password, rendering it invalid.
-s: Modifies the shell used after login.
-u: Modifies the user ID.
-U: Unlocks the password lock.
Additional Notes:
usermod can be used to modify various settings of user accounts.
passwd
1. Purpose
The passwd command is used to change account login passwords; it can be used by all users.
2. Format
passwd [-k] [-l] [-u [-f]] [-d] [-n mindays] [-x maxdays] [-w warndays] [-i inactivedays] [-S] [–stdin] [username]
3. Main Parameters
-k: Sets that the password can only be updated after it has expired.
-l: Locks the named account; only users with superuser privileges can use this.
-u [-f]: Unlocks the account lock status; [-f forces execution]. Only users with superuser privileges can use this.
-d: Deletes the user’s password; only users with superuser privileges can use this.
-n: Minimum password usage time (in days); only users with superuser privileges can use this.
-x: Maximum password usage time (in days); only users with superuser privileges can use this.
-w: Number of days in advance to warn the user before password expiration; only users with superuser privileges can use this.
-i: User expiration date. This parameter specifies the number of days since the user is deactivated (days since January 1, 1970). Only users with superuser privileges can use this.
-S: Checks the password authentication type of the specified user; only users with superuser privileges can use this.