There are several types of IDs for Linux users

青灯夜游
Release: 2023-02-08 09:53:25
Original
2289 people have browsed it

There are two types of Linux user IDs: User ID (User ID, referred to as UID) and Group ID (Group ID, referred to as GID), which correspond to the two attributes of file owner and ownership group. Each file has its own owner ID and group ID. When the file attributes are displayed, the system will find the users corresponding to the UID and GID respectively based on the contents of the "/etc/passwd" and "/etc/group" files. name and group name are then displayed.

There are several types of IDs for Linux users

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

When you log in to the Linux system, although you enter your own username and password, Linux does not actually know your username. It only knows the ID number (that is, a string of numbers) corresponding to the username. The Linux system stores the correspondence between all user names and IDs in the /etc/passwd file.

To put it bluntly, the username has no actual effect, it is just for the convenience of the user's memory.

It is also very simple to prove that "Linux system does not recognize the user name". In the previous chapter, we have downloaded files in the ".tar.gz" or ".tar.bz2" format on the Internet. , in the decompressed file, you will find that the file owner attribute displays a string of numbers. This is normal because the system only recognizes the ID that represents your identity. This string of numbers is the user's ID (UID) number. .

In the Linux system, each user's ID is subdivided into two types, namely user ID (User ID, referred to as UID) and group ID (Group ID, referred to as GID). This is related to the fact that files have owners and The two attributes of owning groups correspond to each other (as shown in Figure 1).

There are several types of IDs for Linux users
Figure 1 The owner and group attributes of the file

As you can see from Figure 1, the owner of the file is the super administrator root and owns the group Also root. Someone may ask, since the Linux system does not recognize the user name, how does the file identify its owner name and group name?

Each file has its own owner ID and group ID. When the file attributes are displayed, the system will find the corresponding UID and GID respectively based on the contents of the /etc/passwd and /etc/group files. The user name and group name are then displayed.

/etc/passwd file and /etc/group file will be explained in detail in subsequent articles. All you need to know here is that in the /etc/passwd file, you can use the UID to find the corresponding User name; in the /etc/group file, the corresponding group name can be found using the GID.

Let’s do a small experiment. In the Linux system used by the author, there are two commonly used accounts, namely the root super administrator account and the c.biancheng.net ordinary account. We first use the root account to log in. And Vim /etc/passwd, find the c.biancheng.net account in the file and change its UID to a random number. Then when you view the files owned by the ordinary account, you will find that the owner of all files is no longer c.biancheng.net, but numbers.

The specific execution process is as follows:

#查看系统中是否存在c.biancheng.net这个用户 [root@livecd ~]#grep 'c.biancheng.net' /etc/passwd c.biancheng.net:x:500:500:c.biancheng.net:/home/centoslive:/bin/bash [root@livecd ~]#ll -d /home/centoslive drwx------. 23 c.biancheng.net centoslive 4096 Apr 9 09:37 /home/centoslive [root@livecd ~]#vim /etc.passwd #修改c.biancheng.net账户中的UID(第一个 500)为 2000 [root@livecd ~]#ll -d /home/centoslive drwx------. 23 500 centoslive 4096 Apr 9 09:37 /home/centoslive #可以看到,之前的 c.biancheng.net 变为了 500,因为修改了UID,导致 500 找不到对应的账号,因此显示数字 #记得最后将其再手动改正过来 [root@livecd ~]#vim /etc.passwd #修改c.biancheng.net账户中的UID从 2000 改为 500
Copy after login

Since the UID of the c.biancheng.net account has been changed to 2000, but its home directory records 500, this user will log in again. I cannot enter my home directory.

Note that in this section, in order to explain the corresponding relationship between ID and user name, the user's UID in the /etc/passwd file has been changed. This operation is likely to cause some programs to fail, so the /etc/passwd file cannot be modified at will.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of There are several types of IDs for Linux users. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!