CentOS7 User Account Management
1. Configuration Files
1.1 User Configuration File
The format contains: username: password: user ID: group ID: comment: home directory: login shell
The 'x' indicates the password is stored separately in /etc/shadow
1.2 Group Configuration File
1.3 Password Storage File
2. Creating Users
When creating a user without specifying a group, a group with the same name as the user is automatically created and assigned to the user
Syntax:
createuser [options] username
Options:
-c #comment, specify a descriptive comment
-d #directory, specify the user's home directory, if it doesn't exist, use -m to create it
-g #group, specify the primary group
-G #group, specify additional groups
-s #shell, specify the login shell
-u #uid, specify the user ID, with -o option, can reuse other user IDs
3. Deleting Users
Syntax:
removeuser [options] username
Options:
-r #remove the user's home directory
4. Modifying Users
Syntax:
modifyuser [options] username
Options:
Common options are similar to 'createuser'
Examples:
1.
modifyuser -s /bin/bash -d /home/john -g dev_ops john_doe
This command changes user john_doe's login shell to bash, home directory to /home/john, and primary group to dev_ops.
2.
modifyuser -G team1,team2 sarah
Replaces sarah's current supplementary groups with team1 and team2
modifyuser -a -G team4 sarah
Adds team4 as a supplementary group while keeping existing ones
modifyuser -l newname oldname
Changes the username
5. User Password Management
Setting user passwords is an important aspect of user management
When a user account is first created, it has no password and is locked until a password is set, even if it's empty
The root user can set passwords for themselves and others, while regular users can only modify their own password
Syntax:
setpass [options] username
Options:
-l #lock the password, disabling the account
-u #unlock the password
-d #remove password, disabling the account
-f #force user to change password on next login
If no username is specified, modifies the current user's password
Examples:
Reset password
Set maximum password lifetime to 180 days
createuser -e 2025-12-31 account1
Set account expiration date (note the format)