
root
使用者能寫入文件,即使write
未設定其權限。
root
使用者能讀取文件,即使其read
權限未設定。
root
使用者能 cd
進入目錄,即使execute
未設定其權限。
root
使用者不能execute
未設定檔案權限時執行檔案。
為什麼?
user$ echo '#!'$(which bash) > file
user$ chmod 000 file
user$ ls -l file
---------- 1 user user 12 Jul 17 11:11 file
user$ cat file # Normal user cannot read
cat: file: Permission denied
user$ su
root$ echo 'echo hello' >> file # root can write
root$ cat file # root can read
#!/bin/bash
echo hello
root$ ./file # root cannot execute
bash: ./file: Permission denied
答案1
簡而言之,因為執行位被認為是特殊的;如果沒有設定根本不,則該文件被認為不是可執行文件,因此無法執行。
然而,即使設定了一個執行位,root 也可以並且將會執行它。
觀察:
caleburn: ~/ >cat hello.sh
#!/bin/sh
echo "Hello!"
caleburn: ~/ >chmod 000 hello.sh
caleburn: ~/ >./hello.sh
-bash: ./hello.sh: Permission denied
caleburn: ~/ >sudo ./hello.sh
sudo: ./hello.sh: command not found
caleburn: ~/ >chmod 100 hello.sh
caleburn: ~/ >./hello.sh
/bin/sh: ./hello.sh: Permission denied
caleburn: ~/ >sudo ./hello.sh
Hello!
答案2
過去,系統管理工具包括/etc
、、、/etc/restore
等。/etc/rrestore
/etc/init
/etc/halt
root
PATH
/etc:/bin
root
passwd
它不會正常工作。
更糟的是,在過去,二進位可執行檔沒有魔術頭,因此除了檢查權限位元之外,檢查二進位檔案是否是可執行檔實際上是不可能的。因此,他們使檔案不是 * 的有效目標,exec
除非它們實際上是檔案(沒有目錄等)並且至少設定了一個執行位元。
*檢查可能是在 execvp 中進行的,這是一個使用者模式函數。
它仍然是一個有用的檢查,因為理論上任何東西都可以是 shell 腳本,那麼為什麼要刪除它呢?