I have two bash scripts within /usr/local/bin and here are the permissions:
-rwxrwx--x 1 root root 33 Dec 30 12:18 hello.sh
-rw-r--r-- 1 root root 34 Dec 30 12:28 test.sh
Both scripts have the same contents:
#!/bin/bash
echo "Hello $USER!"
I am currently a user who does not have root privileges.
I would expect the following:
- I cannot read hello.sh, but I can execute it via
bash hello.sh - I can read test.sh. but I cannot execute it via
bash test.sh
Reading both files works as expected, but execution of both files works opposite of my expectation:
- I cannot execute hello.sh (even though I have execution privileges set for all users)
- I can execute test.sh (even though I only have read privileges set for all users).
I am missing something here. What basic concept am I missing?
>Solution :
I stumbled upon this post: https://unix.stackexchange.com/questions/34202/can-a-script-be-executable-but-not-readable
Ultimately, it appears that bash (the interpreter) is what is actually being executed. The interpreter needs read permissions on the file/script in order to execute the file/script.
So the answer: as long as you have execute permission on your interpreter (in this case bash) and read permissions on the file/script you intend to execute, then you should be good.