linux - 可执行文件是否与运行它的用户具有相同的文件权限?

标签 linux unix file-permissions setuid

在 Unix 中,如果我运行一个包含文件的二进制文件,该二进制文件是否具有与我自己(运行该二进制文件的用户)相同的文件权限?

最佳答案

在大多数情况下,答案是肯定的!

但是,如果您在该二进制文件上启用了 setuidsetgid 位,则情况并非如此。

启用 setuid 的二进制文件的经典示例。

ls -ltra `which passwd`

如果该命令在执行期间无法授予您(执行该命令的用户)与 root 相同的权限来修改 /etc/password/etc/shadow

看看:

https://docs.oracle.com/cd/E19683-01/816-4883/secfile-69/index.html

setuid 权限

When set-user identification (setuid) permission is set on an executable file, a process that runs this file is granted access based on the owner of the file (usually root), rather than the user who is running the executable file. This special permission allows a user to access files and directories that are normally only available to the owner.

setgid权限

The set-group identification (setgid) permission is similar to setuid, except that the process's effective group ID (GID) is changed to the group owner of the file, and a user is granted access based on permissions granted to that group. The /usr/bin/mail command has setgid permissions

如果您想进一步深入了解 Linux 如何管理进程和子进程,您可能还想看看 forkexec

关于linux - 可执行文件是否与运行它的用户具有相同的文件权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50575515/

相关文章:

PostgreSQL PL/PerlU 触发器问题

linux - 反转多个 SED 命令

linux - 将标准输出保存到十六进制文件

php - Ubuntu 到 Windows + php/mysql xml 脚本没有响应

linux - Unix 中的管道。实现示例时出错

android - 如何在 Android 设备中找到所有只读存储?

go - 我应该将 `perm` 参数传递给 ioutil.WriteFile 什么?

linux - 打开多个连接的 usb 设备中的持久名称 ||将 USB 连接到特定端口

linux - 在 buildroot 生成的图像中更新根文件系统

c - C中管道命令的问题