Why can I execute programs without reading them?
$ echo 'echo "foo"' > test && chmod 100 test && ./test
foo
Why can I execute programs without reading them?
$ echo 'echo "foo"' > test && chmod 100 test && ./test
foo
I think your stated test command and case will only work under root
(superuser), based on my tests with the exact same command on my Ubuntu Trusty box.
This is an unprivileged account:
[teward /home/teward/tmp/]% echo 'echo "foo"' > test && chmod 100 test && ./test
zsh: permission denied: ./test
This is as root:
[god /home/teward/tmp/]# echo 'echo "foo"' > test && chmod 100 test && ./test
foo
(Regarding god
on my root prompt: I have root
and my user using zsh
as the login shell. My PS1
for ZSH replaces 'root' with 'god' for the root user on my system, but it's still 'root'. Privilege level is indicated by the character to the right of the closing square brace - the #
indicates root, and %
indicates standard user, which is how you know the privilege level)
I think this is because 'root' is considered god, and can do almost anything. Double-check the user you're using.
Because your shell has to read the file to know what to execute. If you remove read access, it can't read it so doesn't know what you want executed.
root
account as permissions don't matter to it. As a normal user, it cannot be read, so executing a file as a normal user it should say permission denied.