Is it possible to execute a script if there is no permission to read it? In root mode, I made a script and I want the other user to execute this script but not read it. I did chmod to forbid read and write but allow execute, however in user mode, I saw the message that says: permission denied.
|
|
||||
|
|
|
The issue is that the script is not what is running, but the interpreter ( |
|||||||
|
|
This is possible only for binaries.
As the unprivileged user:
Now, here is the kicker. While the file is unreadable by conventional means, you can't actually prevent reading the file. This is actually a challenge on http://smashthestack.org/ (level 13). There is a well known utility called |
||||
|
This is not possible; think about it, when you run the script, the shell needs to read it in order to know what to do. |
|||
|
|
|
You can, I think, do this with Except that you can't because most distros (apparently) have Anyway, if I wanted to do what you wanted to do--and I had a distro with
Which is to say I would write another script whose sole purpose is to call the root-read-only script, change it to be owned by root, and give it the setuid permission. (Along with attendant non-writable status by everyone else.) Since the myscript-nonroot function is readable by everyone it can be read and executed, and by the time you get two the line where you actually execute your script ( |
|||||||||
|
|
On this situation I used sudo with a NOPASSWD option so the users can run the script without being able to read it. |
|||
|
|
