在 Unix 中,如果我运行一个包含文件的二进制文件,该二进制文件是否具有与我自己(运行该二进制文件的用户)相同的文件权限?
最佳答案
在大多数情况下,答案是肯定的!
但是,如果您在该二进制文件上启用了 setuid
、setgid
位,则情况并非如此。
启用 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 如何管理进程和子进程,您可能还想看看 fork
和 exec
。
关于linux - 可执行文件是否与运行它的用户具有相同的文件权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50575515/