[英]-SUID- Can't run a “-rwsr-xr-x” file as root
I am using Ubuntu 16.10. 我正在使用Ubuntu 16.10。
I was following along a book, doing something like this: 我沿着书走,做着这样的事情:
#include <stdio.h>
int main() {
printf("Real UID:\t%d\n", getuid());
printf("Effective UID:\t%d\n", geteuid());
}
And to run this file as sudo without using the sudo command, after compiling with gcc, I changed the owner and group to root. 为了在不使用sudo命令的情况下以sudo形式运行此文件,在使用gcc编译后,我将所有者和组更改为root。
$ gcc -o test test.c
$ sudo chown root:root ./test
$ chmod u+s ./test
$ ls -l
-rwsr-xr-x 1 root root 8512 Mar 9 test
Now, this is what I got when I executed the file. 现在,这就是我执行文件时得到的。 My UID is 1000.
我的UID是1000。
$ ./test
Real UID: 1000
Effective UID: 1000
The book I was reading said the result should be like this: 我正在读的书说结果应该是这样的:
$ ./test
Real UID: 1000
Effective UID: 0
The UID for root is 0, right? 根的UID是0,对吧? Does this mean that I am running an -rwsr-xr-x file, owned by root, with my own user privilege?
这是否意味着我正在以我自己的用户权限运行-rwsr-xr-x文件,该文件由root拥有? I don't understand.
我不明白
Is your book a little on the older side? 您的书偏旧吗? It seems like modern *nix variants widely ignore the sticky bit on executable files:
似乎现代* nix变体广泛忽略了可执行文件上的粘滞位:
[...] the Linux kernel ignores the sticky bit on files.
[...] Linux内核会忽略文件上的粘滞位。 [...] When the sticky bit is set on a directory, files in that directory may only be unlinked or renamed by root or the directory owner or the file owner.[4]
[...]在目录上设置粘滞位时,该目录中的文件只能由root或目录所有者或文件所有者取消链接或重命名。[4]
https://en.wikipedia.org/wiki/Sticky_bit https://zh.wikipedia.org/wiki/Sticky_bit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.