I create a bash script in the user directory that, when executed, for example, displays the text "Hello world". At the same time, I want to be able to execute it only myself (the owner of the file) and the accounts from my group, and all the rest could just read. Accordingly, I set the rights through chmod, I log in as a user not from my group, go to the directory with the file, run it through sh and ... it suddenly executes and displays "Hello world" instead of "Access denied". But how is this possible, I forbade others to perform? What it is? What does it mean?
[user@localhost ~]$ ls -la *.sh
-rwxr-xr-- 1 user users 0 Feb 19 01:21 file.sh
[user@localhost ~]$ sh file.sh
Hello World
[user@localhost ~]$ groups
users wheel
[user@localhost ~]$ su - testu
Password:
[testu@localhost ~]$ groups
testu
[testu@localhost ~]$ cd ../user
[testu@localhost user]$ sh file1.txt
Hello World```
sh
they pass the script's contents as an argument intosh
which they absolutely CAN execute. Also, where did you change thesh
extension totxt
?sh
, yes, but i only pointed it out as its inconsistent with the previous filename. Execution rights are used mostly by binary files which aren't read into a shell interpreter like sh, bash, etc, but are bytes directly decoded by the CPU.sh
itself is the binary but it acts as the interpreter. If you make a hello world program in C, and compile, its not interpreted bysh
any more, its executed by the CPU to give you the output - in this case, execution rules apply.setuid
and will execute under the owner's user account regardless of who's actually executing it or when the code's behavior depends on the location/path of the executable file and you don't want certain users to be able to execute it in that location.