/etc/passwd
Linux system saves user information in file/etc/passwd
A row in a file represents a user, so the number of rows in a file represents how many users the system has. Each line is divided into 7 fields separated by colons, and we first understand what these fields mean.
As described in the first line of system administrator account root
Field 1:root------on behalf of user name
Field 2:X------On behalf of this user's login password, for security reasons, the password in this file is shown in X, the user's real password is saved in the shadow file, that is,/etc/shadow
Field 3:0------represents the UID (user ID) of this user
Field 4:0------The GID representing this user (the group ID that the user belongs to)
Detailed description of the field 5:root------user
Field 6:/root------User's home directory
Field 7:/bin/bash------The type of script used by the user
The UID is 0, which is root and has the highest system privileges. 1-499 is the system reserved account, user-created account often after 500
/etc/shadow
Similar to/etc/passwd,/etc/shadow is divided into 9 fields by a colon
Field 1: User account, such as root. This field represents a user account that must exist in/etc/passwd
Field 2: Password, this password is an encrypted password. $6$, such as the root user's password, represents the use of SHA-512 encryption, $1$, represented by MD5 encryption; $2$, represented by Blowfish encryption; $5$, represented by SHA-256 encryption. We will also see that the account password in the diagram is "*" or "!!", and these special characters often represent special meanings. "*" on behalf of the account is locked, "!!" On behalf of the password has expired
Field 3: The date the password was last modified. But we will notice that this field is not displayed in the date format we are familiar with, but in numbers such as 17110. The reason is that Linux will be January 1, 1970 as 1,17110, which is the number of days between January 1, 1970 and last modified password
Field 4: The number of days the password cannot be changed. If it is 0, it can be modified at any time, such as the root account can change their password at any time, and if it is 8 or 20 such a number greater than 0, indicating that the account in 8 days or 20 days of non-modifiable password
Field 5: The age at which the password needs to be modified. If it is 99999, such as root, indicating that the user can not change, and if it is another number, such as 12345, it means that the password must be changed within 12,345 days from January 1, 1970, otherwise the password expires
Field 6: The warning period before the password change period. If the 5th field has a password that must be modified on a certain day, the system will warn the user of the change password before the number of days set in this field, so that the field is set to 6, the user will be alerted 6 days before the password needs to be modified.
Field 7: The expiration date of the password, which is the same as field 3, and is determined by the number of days from January 1, 1970. If it is set to M days, the password can be modified within m days after the account expires, and the account can continue to be used after the modification.
Field 8: The expiration date of the account, same as Field 3, if it is set to n days, then n days, the account cannot be used
Field 9: System reserved field, no actual meaning
User account operation
After knowing some information about the account, we will have to create the user, modify the user, delete the user's needs
Create or add a user account, we can use the Useradd command to complete
If we add a test user, and then see the/ETC/PASSWD system has generated information about this user, the system will create a user with the same GID and UID group, and the default home directory and Shell type
We can also use other parameters of Useradd to help us create accounts that meet our requirements.
such as: Useradd-p 123456 testUser When creating a user TestUser, assign a password to it
View/etc/passwd, the system has generated the relevant information. Now that we've given the user a password, I'll take a look at the password file.
We can see in the second field that the password given at the time of creation has been saved.
When explaining the/etc/shadow file, we learned that the password stored in this file is ciphertext, and that the password of the TestUser user is clear text. Let's take a look at how the Useradd-p parameter is used
Originally, the password after useradd-p should be encrypted password (encrypted password), because the password when creating testuser is not encrypted, so/etc/shadow will be displayed in clear text
Useradd-u 1666 TestUser1 When creating a testUser1, specify its UID
Useradd-g TestUser2 When creating TestUser2, specify its GID
It is worth noting that the GID assigned to the user must be in the real system, otherwise it will be reported: Useradd:group ' does not exist
There are many other parameters that we use, and when we want to understand the detailed usage of a command, you can use the "man command" to see the detailed usage of this command.
After creating the user, we may need to modify the user's information, Usermod can help you to complete the work
such as modifying the GID and UID of the TestUser1
TestUser1 's original UID and GID are all 1666, now we use Usermod to modify
After modification, the GID and UID of testUser1 in/etc/passwd changed, same as Useradd, the changed GID must be the real one in the system.
Usermod also has a lot of other useful parameters
We will gradually become acquainted with them in our daily use.
Modify user's password such as: passwd testUser1 modify TestUser1 's password
The system will let you enter a new password and confirm the password, when the password is too short or too simple, the system will give a warning message
When you view/etc/shadow again, TestUser1 has been set up with a new password
Delete User Userdel TestUser2 Delete testUser2
We can see that TestUser2 has been removed
User management of Linux learning