Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
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
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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