Score:0

Execute permissions for all users not working as expected

mp flag

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?

Score:0
mp flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.