In Linux, the password of root is stored in the /etc/shadow file. Only the root permission can find the /etc/shadow file in linux.
Viewing the /etc/shadow file contains sensitive information that can only be viewed by root users and users with specific permissions:
sudo cat /etc/shadow
In the /etc/shadow file, each line corresponds to a user. Fields are separated by colons (:). User name indicates the login name of the user, and encrypted password indicates the encryption password of the user. The fields are usually */! , indicates no password/password lock. The last time the password was changed is the number of days since UTC. The minimum age of a password is the number of days after the password is changed that it cannot be changed again. The maximum age of a password is how many days it must be changed. Warning days is how long before the password expires to warn the user. Inactive days refers to the number of days after a user's password expires that the account is automatically locked. Account expiration time is the number of days from UTC, indicating the expiration time of the account. If the value is -1, the account will never expire.
You can change the user password by:
sudo passwd username
To change tom's password:
sudo passwd tom
After you run the preceding command, the system prompts you to enter a new password and confirm it.
If you want to lock a user account:
sudo usermod -L username
Lock user tom:
sudo usermod -L tom
Precede the user's password field in the /etc/shadow file! , indicates that the password is locked. Unlock User account:
sudo usermod -U username
You can also set a password policy. For example, the maximum password age of tom is 90 days.
sudo chage -M 90 tom
The minimum age of tom is 7 days:
sudo chage -m 7 tom
View User tom Password policy:
sudo chage -l tom
Delete user password:
sudo passwd -d username
All operations can be performed only by the root user and authorized system administrator. You need to periodically check the /etc/shadow file to ensure that no abnormal password policy or lock status exists. A strong password policy allows you to set the minimum length and complexity of a password and update the password periodically. Back up the /etc/shadow file to prevent password related files from being lost or damaged.