我目前正在嘗試了解檔案權限中的特殊位的作用,但目前我一直在試圖了解 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
我的期望是,當設定了 setuid 位時,腳本應該以原始用戶身份執行,因此應該具有ls進入受限目錄的權限。但相反,我收到了一個權限被拒絕錯誤,表明該腳本沒有以原始用戶身份運行。
任何幫助理解我做錯了什么將不勝感激。(示例在 zsh / ubuntu 20.04 / wsl2 上運行)
uj5u.com熱心網友回復:
suid 位僅適用于二進制可執行程式,不適用于 shell 腳本。您可以在此處找到更多資訊:https : //unix.stackexchange.com/questions/364/allow-setuid-on-shell-scripts
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/358164.html
上一篇:如何在Ubuntu中將Java版本1.7更改為1.8?
下一篇:了解QtService中的后端
