実行可能ビットが設定されていないとルートを実行できないのはなぜですか?

実行可能ビットが設定されていないとルートを実行できないのはなぜですか?

rootユーザーできるwrite権限が設定されていない場合でもファイルに書き込みます。

rootユーザーできるread権限が設定されていない場合でもファイルを読んでください。

rootユーザーできる cdexecute権限が設定されていない場合でもディレクトリを入力してください。

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

つまり、実行ビットが設定されていない場合は特殊と見なされるためです。別の言葉、そのファイルは実行ファイルではないと見なされ、実行できません。

ただし、ルートは実行ビットが設定されていても実行でき、実行されます。

観察する:

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!

おすすめ記事