In Linux, each file has its own users and groups of users, by default the creator of the file, or by Chown and chgrp, to modify the users and user groups to which the file belongs. The properties of the file are stored in the attribute structure stat, which is marked by St_uid and St_gid.
Let me give you an example. Suppose that there are now two users in the system, Liz and HLF, who have a program file whose user is HLF. Then use the Liz User login system to run the file, then the running process has an actual user and a valid user, the actual user defaults to the current logged-on user, that is, Liz. and the effective user. Which of the valid users depends on the file's properties, property structure Stat has a St_mode file mode word, which has a setting-user-id bit, if not set this bit, then any process that executes the file files The valid user is its actual user; If this bit is set, The active user of the process executing the file files is the user who owns the file. Here, if the bit is set, the valid user is HLF, otherwise the actual user Liz.
Here you need to explain the effect of the actual user ID and the valid user ID. The actual user is used to identify who the process is, who is executing the process, typically the logged-on user, and the valid user ID identifies the process's access rights, assuming that the actual user of the process is Liz and that the active user is HLF, then the process can access files that the HLF user can access. You have the same permissions as HLF (note that you are not able to access HLF files).
Here's a procedure to illustrate the whole process.
First, we use the root user to generate an executable file, test.
The owner of the test file is then changed to the HLF user.
Then use the Liz user to log on to the system, execute the test file, according to the theory, no settings-user-id bit, then the process's actual user ID and valid user ID are Liz. Let's look at what the user ID is, and the system user ID number is stored in the/etc/passwd file.
Then the result of running the test file after Liz logs in is as follows:
You can see that both the actual user and the effective user are 1000, that is, Liz. Now let's change the settings for the test file-user-id bit.
And then run the test file in Liz with the following results:
As you can see, the valid user ID becomes 1001, which is HLF.