I never understood this, because if you have access to read a file, doesn't that mean you would be able to copy it somewhere else, thus allowing you to execute it anyway?

What am I missing?

  • +1 Coming from a DOS/Windows background I recall wondering the same thing the first time I used Linux. – John Gardeniers Oct 18 '10 at 23:23

The Executable flag is there to indicate to the kernel that the data should be read and then run. This is implemented by having a different call for executing something and reading something. For compiled programs it is quite possible to have execute-only access to it and not have read access; you can't even 'cp' them elsewhere. For interpreted items like shell-scripts, read is needed for execution.

I know one Linux distro that uses the execute flag to control what scripts fire at bootup.

In short, the Execute flag is used to indicate the ability of compiled code to run. Interpreted code is run through the parent processor and may only need 'read'.


Some potential reasons:

  • It protects the file from being accidentally executed.
  • It's obvious this way what files are executables (on Windows you need to check the registry for the list of executable file extensions to know that)
  • It protects you against some security exploits (attackers do not only need a way to put a file on your system and somehow execute it, they also need a way to change its permissions).
  • If the only disks the user can write to have an umask/mount option that "removes" the execute bit, they can't copy it somewhere else and make it executable (at least, not on that machine, and you might have to take other precautions too)

There are probably other reasons...

  • The most important one that you sort-of covered but not explicitly - Prevents a user from loading a remote file onto the system, then executing that file locally on the system. – Chris Thorpe Oct 17 '10 at 5:32
  • It doesn't really prevent a user from doing that (unless precautions are taken like I mention in my last point). – JanC Oct 17 '10 at 18:30

doesn't that mean you would be able to copy it somewhere else, thus allowing you to execute it anyway?

No, this is not correct.

There are scenarios when you can't execute a file, even if it has the executable bit set. Here are at least two of them:

  • a restricted shell which explicitly prohibits execution
  • a filesystem mounted with noexec option

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.