Detailed explanation of the contents of Linux /etc/passwd

1. What does the /etc/passwd file do?

The /etc/passwd file in the Linux system is a system user configuration file, which stores the basic information of all users in the system, and all users can perform read operations on this file.

Let's take a look at what's in this file first

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
...太多了,省略一部分...
skx:x:1000:1000:ubuntu-18.04.1,,,:/home/skx:/bin/bash
lilei:x:1001:1001:,,,:/home/lilei:/bin/bash

Each line in the file represents a user.

Open the file and you can see that there are many lines, how come there are so many users? The vast majority of these users are users necessary for the normal operation of the system or service, and such users are usually called system users or pseudo users. System users cannot be used to log in to the system, but they cannot be deleted, because once deleted, services or programs that rely on these users to run will not be able to execute normally, which will cause system problems.

The format of each line in the file is as follows. There are 7 fields in total, separated by ":". The functions are described below

用户名:密码:UID(用户ID):GID(组ID):描述性信息:主目录:默认Shell

2. Detailed explanation of fields

2.1 Username

root, skx, lilei These are all user names. User names are only for the convenience of users to remember. The Linux system uses UID to identify users and assign user permissions. The corresponding relationship between user name and UID is defined in the /etc/passwd file.

2.2 Password

"X" means that this user has a password, but it is not a real password. The real password is stored in the /etc/shadow file.

In early UNIX, the real encrypted password string is stored here, but since all programs can read this file, user data is easy to be stolen (which can be brute-forced). Now the Linux system puts the real encrypted password string in the /etc/shadow file, this file can only be browsed and operated by the root user, so as to maximize the security of the password.

Note: "x" cannot be deleted. If "x" is deleted, the system will think that this user does not have a password, which leads to login by only entering the user name without entering the password.

2.3 UID

UID, which is the user ID. Each user has a unique UID, and the Linux system uses UID to identify different users.

In fact, UID is a number between 0 and 65535. Numbers in different ranges indicate different user identities, as shown in Table 1.

UID range user ID
0 Super user, administrator account. How to upgrade ordinary users to administrators in Linux? Just change the UID of other users to 0
1~499 System user (pseudo user). The UID in this range is reserved for system use. Among them, 1~99 are used for accounts created by the system; 100~499 are allocated to users with system account requirements.
Except for 0, all other UIDs are the same. By default, numbers below 500 are just a recognized habit for the system.
500~65535 general user

2.4 GID

The full name "Group ID", or "Group ID" for short, represents the group ID number of the user's initial group. Here need to explain the concept of initial group and additional group.

  • The initial group means that the user has the relevant permissions of this user group when logging in.
  • An additional group means that a user can join multiple other user groups and have the permissions of these groups.

To put it simply, user A belongs to the initial group A, and now has joined the group B, A belongs to two groups at the same time, group A is the initial group, and group B is the additional group.

The group ID in the /etc/passwd file is the initial group ID.

2.5 Descriptive information

Used to explain the meaning of this user, no important purpose

2.6 Home Directory

That is, the access directory for which the user has operation authority after logging in is usually called the user's home directory. Switching users enters this directory by default.

2.7 Default Shell

Shell is the command interpreter of Linux and the bridge between users and the Linux kernel.

The system only recognizes 0101 machine language. We use Linux commands to complete the operation tasks, which requires the use of a command interpreter. In other words, the function of the Shell command interpreter is to convert the commands entered by the user into machine language that the system can recognize.

Under normal circumstances, the default command interpreter used by the Linux system is bash (/bin/bash), of course, there are other command interpreters, such as sh, csh, etc.

Reference link: http://c.biancheng.net/view/839.html

Guess you like

Origin blog.csdn.net/happyjacob/article/details/109701341