> out.txt $ ls -l out.txt phone.sh --6ren">
gpt4 book ai didi

bash - 在文件上设置 suid 运行 bash 脚本

转载 作者:行者123 更新时间:2023-11-29 09:13:25 25 4
gpt4 key购买 nike

我写了一个小的 bash 脚本来测试 suid 权限

$ cat phone.sh
#!/bin/sh
echo "abc" >> out.txt

$ ls -l out.txt phone.sh
-rw-r--r-- root wzj ... out.txt
-rwsr-xr-x root wzj ... phone.sh

$ ./phone.sh
./phone.sh: 2: cannot create out.txt: Permission denied

为什么?我以为我已经设置了 suid 权限,所以我可以以 root 权限运行 phone.sh 来修改 out.txt 文件,但我只是失败了。谁能告诉我哪里做错了吗?

最佳答案

大多数 *nix 操作系统不允许脚本使用 SUID。查看Vidar's blog entry就此主题而言。 Perl 脚本可以使用 SUID,但正如 Vidar 解释的那样,这取决于 Perl 的实现方式。看来 Bash 脚本根本无法使用 SUID 运行。抱歉,我没有对您更有用的答案,看起来这只是“情况如何”。

关于bash - 在文件上设置 suid 运行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11418161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com