Shell scripts require the read permission to be executed, but binary files do not:
$ cat hello.cpp
#include<iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
$ g++ -o hello hello.cpp
$ chmod 100 hello
$ ./hello
Hello, world!
$ file hello
hello: executable, regular file, no read permission
Displaying the contents of a file and executing them are two different things. With shell scripts, these things are related because they are "executed" by "reading" them into a new shell (or the current one), if you'll forgive the simplification. This is why you need to be able to read them. Binaries don't use that mechanism.
For directories, the execute permission is a little different; it means you can do things to files within that directory (e. g. read or execute them). So let's say you have a set of tools in /tools
that you want people to be able to use, but only if they know about them. chmod 711 /tools
. Then executable things in /tools
can be run explicitly (e. g. /tools/mytool
), but ls /tools/
will be denied. Similarly, documents could be stored in /private-docs
which could be read if and only if the file names are known.
cd
to it. – gardenhead Mar 11 '17 at 00:19stdio.h
here. I suggest removing it. – Spikatrix Mar 11 '17 at 04:19/etc/
and friends? Not a lot of "typical" software needs to enumerate those directories. – Kevin Mar 11 '17 at 08:12ls
and tab completion working makes maintenance work annoying, and it provides little if any actual security benefit. Most of the files that an attacker could be interested in are at known standard locations anyway, or their locations can be discovered indirectly from data in other files (else how would the programs that legitimately use those files know where to find them?). – Ilmari Karonen Mar 11 '17 at 16:08/etc
to know how to behave properly./etc
is, among other things, the common location for default settings (e. g./etc/profile
) or messages (/etc/motd
). – DopeGhoti Mar 11 '17 at 16:10/etc
. – Kevin Mar 11 '17 at 17:16public_html
directory (which has read permission for other). – Simon Richter Mar 12 '17 at 01:21