Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Execute permissions for all users not working as expected

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading