Are read and execute permissions equivalent?

If one has read permission, they can just read the contents, copy them in a new file, add execute permission to that new file, and execute the new file.

If one has execute permission, then the file instructions have to be read, and hence read permission is implied.

What am I missing here? Are read and execute permissions essentially the same? Does one imply the other?

  • 1
    If you copy the the file, its path or name are different. Both these features can change the programme's behaviour. – choroba May 7 '13 at 22:14

For files, having one permission set but not the other makes sense only if the file also has the "setuid" or "setgid" bit set, or if it was given various capabilities using setcap. If you make your own copy of the executable, it will not be able to obtain the same privileges, since only root can preserve the original owner or change file capabilities.

For directories, "execute" means "traverse directory" – it is needed to access the directory's contents. If you have +x but not +r, then you can access files inside, but you must know their names. If you have +r but not +x, you can list (read) the file names stored in that directory, but not access the actual files.

  • 6
    Even without setuid/setgid, It can make sense to have +r and not +x. Think about an upload directory on a webserver. Perhaps you want to allow users to upload avatar images - you would want the files to be marked as +r so the images can be read by the server, but not +x so that if they try to upload a malicious virus and trick the server into executing it, it might fail (depending on the method of attack). – Darth Android May 7 '13 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.