Linux user account management - modify user password status
In the Linux system, we can use the chage command to modify the user's password status. Through this command, we can view and modify the user's password information, and can also force the user to change the password after logging in to the system for the first time, so as to improve the security of the system.
chage Command Syntax
The basic syntax of the chage command is as follows:
chage [选项] 用户名
Among them, commonly used options include:
options | describe |
---|---|
-l | List user's detailed password status |
-d date | Change password last modified date |
-m number of days | Change password minimum retention days |
-M days | Modify password validity period |
-W days | Change the number of warning days before password expiration |
-i number of days | Change the number of grace days after password expiration |
-E date | Modify account expiration date |
Practical exercise
Next, we go through a hands-on walkthrough to view and modify a user's password status.
Step 1: View user password status
Let's first check the current password status of the user, using the command:
chage -l 用户名
For example, to view the password status of user root, execute the following command:
chage -l root
After executing the above command, the detailed password status of the user will be displayed, for example:
Last password change: May 01, 2023
Password expires: Aug 29, 2023
Password inactive: never
Account expires: never
Minimum number of days between password change: 0
Maximum number of days between password change: 90
Number of days of warning before password expires: 7
The above information respectively indicates the time when the password was last changed, the password expiration time, how long the password expires after it has not been used, the account expiration time, the minimum password retention days, the longest password retention days and the number of warning days before the password expires.
Step 2: Modify user password status
If you need to modify the user's password status, we can use the options provided by the chage command to achieve. For example, if you need to extend the password validity period of user root to 120 days, you can execute the following command:
chage -M 120 root
In this command, the option -M indicates that the valid period of changing the password is 120 days, and the user name is root.
Comparison of methods for modifying user password status
In addition to modifying the user password status through the chage command, you can also directly modify the /etc/shadow file to achieve the same function. The table below lists the differences between the two methods.
method | advantage | shortcoming |
---|---|---|
chage command | Easy to operate, not easy to misuse | Changing password status requires remembering a lot of options |
Modify the /etc/shadow file directly | Convenient and fast, you can modify the password status of multiple users at one time | Improper operation may cause system problems, and sufficient permissions are required |
in conclusion
This article introduces how to modify user password status in Linux system. Through the chage command or directly modifying the /etc/shadow file, we can easily view and modify the user's password status, thereby improving the security of the system. It should be noted that when modifying the password status, the correct operation must be ensured, and the user password information must not be disclosed to ensure the security of the system.