当你作为 root 用户生成时,你可以使用 euid,你需要暂时放弃特权,但是仍然可以恢复 root 用户的特权,就像 man setuid (2) :
Thus, a set-user-ID-root program wishing to temporarily drop root privileges, as‐
sume the identity of an unprivileged user, and then regain root privileges after‐
ward cannot use setuid(). You can accomplish this with seteuid(2).
您还可以使用它来提高 setuid 程序的特权。如果你的有效用户 id 是 root,那么一切都会像你是 root 一样,除了我认为唯一的例外是文件访问检查会检查你的真实用户 id 而不是有效用户 id,这是一个混淆的来源,就像 man access (2) :
The check is done using the calling process's real UID and GID, rather
than the effective IDs as is done when actually attempting an operation
(e.g., open(2)) on the file. Similarly, for the root user, the check
uses the set of permitted capabilities rather than the set of effective
capabilities; and for non-root users, the check uses an empty set of
capabilities.
在调用 bash 时,除非像 man bash (1)那样传递 -p,否则它不会传播 euid:
If the shell is started with the effective user (group) id not equal to the real
user (group) id, and the -p option is not supplied, no startup files are read,
shell functions are not inherited from the environment, the SHELLOPTS, BASHOPTS,
CDPATH, and GLOBIGNORE variables, if they appear in the environment, are ignored,
and the effective user id is set to the real user id. If the -p option is sup‐
plied at invocation, the startup behavior is the same, but the effective user id
is not reset.
在使用 sudo 时,有效用户 ID 和实际用户 ID 都设置为 man sudo (8) :
When sudo executes a command, the security policy specifies the execution environ‐
ment for the command. Typically, the real and effective user and group and IDs are
set to match those of the target user, as specified in the password database, and
the group vector is initialized based on the group database (unless the -P option
was specified).