4

I want to grant execute permission for a script, but not read permission since I do not want user to read the content for the script. But it seems not working, I post what I am doing and seeking for advice,

sub-directory demo is owned by root user and root group,

Case 1, make execute+read permission, works

chmod 775 /home/yhd/demo/text

Then user yhd can execute text command without any issues

Case 2, make execute permission only, not working

chmod 771 /home/yhd/demo/text

Then user yhn cannot execute text command, and error message is permission denied

2 Answers 2

6

The problem with scripts is that the script is not what is running, but the interpreter (bash in this case).

The interpreter needs to read the script.

Since reading the file is forbidden then it can't be executed inside the interpreter.

This is different from a program, because programs are loaded directly into memory.

One solution is to use a compiler that will generate a C program equivalent to the script, like SHC, that you can download from here or from this guide.

2
  • Thanks for all the help jcbermu, mark your reply as answered.
    – Lin Ma
    Feb 23, 2016 at 3:47
  • so file permissions don't just apply to human users, but other programs as well? Feb 10, 2021 at 1:48
5

how to grant execute permission without read permission?

Nope, is not possible: the interpreter needs to read script. What @jcbermu means is this one: https://unix.stackexchange.com/questions/34202/can-a-script-be-executable-but-not-readable

1
  • 1
    Vote up nice reply. Thanks for all the help duDE, nice name. :)
    – Lin Ma
    Feb 23, 2016 at 3:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .