The permission to run ‘ls’ is denied

command-line-interfacepermissions

I'm running my server as a root user but despite that, when I run the command ls I get this error:

bash: /bin/ls: Permission Denied.

I tried to change this file's permissions with chmod but the permission is denied as well. What's the cause of this?

Best Answer

There are several potential causes for this.

  1. The filesystem is mounted noexec.
  2. Filesystem corruption that needs to be fixed with fsck.
  3. The filesystem is foreign and improper translation of permissions results in denied privileges.
  4. The directory holding the binary does not have the execute bit set (causing an issue with traversal)
  5. A sub-directory in the directory does not have the execute bit set (only applies if the binary is nested in more than one directory)
  6. The binary does not have the read and execute bits set for your user ID or group ID.
  7. You are not really root (UID 0), even though the account name says root. While improbable, this is possible. Note that root is not 100% the same as UID 0, which is a "special" ID that bypasses privilege checks. The root account, however, is mapped to UID 0.
  8. SELinux/grsecurity rules denying everything. (thanks Janne Pikkarainen! had a little mental block about that annoyance.)
  9. One or more binaries are compromised. In which case, you can't trust anything you are running.

More information is needed to really understand what is happening.