gow*_*erc 2 ubuntu file-permissions
我目前正在尝试了解文件权限中的特殊位的作用,但目前仍试图了解 setuid 位的作用。从所有在线资源来看,它说:
通常称为 SUID,用户访问级别的特殊权限具有单一功能:具有 SUID 的文件始终以拥有该文件的用户身份执行,无论用户传递命令如何
然而,在一个简单的实验中,这似乎并不正确(除非我误解了并且做错了什么?)即
mkdir /tmp/foo
mkdir /tmp/foo/bar
chmod 0700 /tmp/foo/bar # Restrict directory so only current user can access
echo content > /tmp/foo/bar/baz.txt # Create content in the restricted directory
echo "ls /tmp/foo/bar" > /tmp/foo/myscript.sh # Script to access content of restricted directoy
chmod 4777 /tmp/foo/myscript.sh # Set setuid bit so the script runs as current user
/tmp/foo/myscript.sh # Show it works when run as current user
#> baz.txt
su bob # Switch to a new user
/tmp/foo/myscript.sh # Run script again
#> ls: cannot open directory '/tmp/foo/bar': Permission denied
Run Code Online (Sandbox Code Playgroud)
我的期望是,当设置了 setuid 位时,脚本应该以原始用户身份执行,因此应该有权进入ls受限目录。但相反,我收到了权限被拒绝错误,表明该脚本未以原始用户身份运行。
任何有助于理解我做错了什么的帮助将不胜感激。(示例在 zsh / ubuntu 20.04 / wsl2 上运行)
suid 位仅适用于二进制可执行程序,不适用于 shell 脚本。您可以在这里找到更多信息:https://unix.stackexchange.com/questions/364/allow-setuid-on-shell-scripts
| 归档时间: |
|
| 查看次数: |
1150 次 |
| 最近记录: |