Detailed explanation of /etc/shadow directory in Linux system
In the Linux system, the /etc/shadow directory is a file directory used to store user password information, also known as a "shadow file". Only the root user has read permission for this directory, and other users cannot directly view or modify files in this directory.
The following will introduce the /etc/shadow directory from three aspects: syntax, practical operation, and the differences between different /etc/shadow directories.
grammar
Each line in the /etc/shadow directory represents a user's password information record, using a colon (:) as a separator, and includes the following 9 fields:
field | describe |
---|---|
username | user's login name |
encrypted password | Password string encrypted by SHA512 hash algorithm |
last modified time | Total number of days since January 1, 1970 |
Minimum Modification Interval | From the third field, how long the password cannot be changed |
password validity period | How long before the third field (last password change) needs to change the password again |
Number of warning days before password needs to be changed | When the account password expires soon, the system will send a warning message to the account |
Grace time after password expires | After the password expires, if the user has not changed the password, the user can still log in to the system within the grace days specified in this field |
account expiration time | As with the 3rd field, use the total number of days since January 1, 1970 as the expiry time of the account |
reserved text | currently not used |
Practical
View /etc/shadow file
The contents of the file can be viewed using cat
the command or less
commands /etc/shadow
.
$ cat /etc/shadow
$ sudo less /etc/shadow
Modify user password
Use passwd
commands to modify user passwords. When executing the command, the system prompts for a new password and then confirms the password again.
$ sudo passwd username
The difference between different /etc/shadow directories
On some Linux systems, there may be multiple /etc/shadow
files, and the differences between them are described below.
/etc/shadow
This is the most commonly used /etc/shadow
directory for storing user password information, and only the root user has read permission.
/etc/shadow-
/etc/shadow-
The directory is to /etc/shadow
back up the file when the file is changed, in case of accidents during the modification process, the problem can be solved by restoring the backup file.
/etc/gshadow
/etc/gshadow
The directory is used to store the management information of the group, and /etc/shadow
similar to that, only the root user has read permission.
/etc/gshadow-
/etc/gshadow-
The directory is to /etc/gshadow
back up the file when the file is changed, in case of accidents during the modification process, the problem can be solved by restoring the backup file.
Summarize
/etc/shadow
The directory is the file directory for storing user password information in the Linux system, and only the root user has read permission. The directory contains 9 fields such as user name, encrypted password, last modification time, and password validity period. At the same time, there are other different /etc/shadow
directories, such as /etc/gshadow
and, /etc/shadow-
etc., you need to pay attention to the difference between and when managing user passwords /etc/shadow
.