EACCES During Path Traversal
EACCES means the kernel could not traverse the path because some directory component lacks search (x) permission for your effective user, or the final file lacks the requested access; the error does not identify the component. Check every ancestor with namei -l and inspect modes, ACLs, and mount options rather than only the leaf file.
The short answer
EACCES is errno 13, "Permission denied". During path resolution the kernel must traverse every directory component, and traversal requires execute (search) permission on each directory for the effective user and group. If any component denies search, the system call fails with EACCES and the error names only the full path, never the component that refused. The same code also covers a final file that lacks the requested read or write permission, so the failing object may be the file rather than a directory.
A minimal example
sudo mkdir -p /srv/private/data
sudo sh -c 'echo hello > /srv/private/data/report.txt'
sudo chmod 700 /srv/private
sudo chmod 644 /srv/private/data/report.txt
ls -l /srv/private/data/report.txt
# ls: cannot access '/srv/private/data/report.txt': Permission denied
sudo -u nobody cat /srv/private/data/report.txt
# cat: /srv/private/data/report.txt: Permission denied
The file mode is 644, which grants read to everyone, yet an unprivileged user still fails. The blocker is /srv/private, whose mode 700 denies search to anyone but root. namei -l walks the path and prints each component's mode, which localises the problem quickly:
$ sudo namei -l /srv/private/data/report.txt
f: /srv/private/data/report.txt
drwxr-xr-x root root /
drwxr-xr-x root root srv
drwx------ root root private
drwxr-xr-x root root data
-rw-r--r-- root root report.txt
Why directories are the usual suspect
Directories use their permission bits for different operations than files:
| Bit on a directory | Allows |
|---|---|
r |
list names with ls and readdir |
w |
create, delete, and rename entries |
x |
traverse through the directory; stat and open entries by name |
Reading a file needs x on every ancestor and r on the file itself; listing a directory needs r but not x; deleting an entry needs w and x on the directory, not on the file. A directory can therefore be readable but not traversable, which produces EACCES on a path whose leaf is world-readable. POSIX defines this search check as part of pathname resolution, and the Linux reference is path_resolution(7).
Finding the denying component
Work from the root down. namei -l is the fastest tool, and ls -ld on each prefix shows the same modes. Access checks must run as the same user that fails, because root bypasses most checks and because group membership differs per account.
sudo -u www-data namei -l /srv/private/data/report.txt
sudo -u www-data test -x /srv/private && echo ok || echo blocked
getfacl -p /srv/private 2>/dev/null
ACLs matter as much as the mode string: ls -l shows a + when an ACL is present, and getfacl shows the effective entries. Network mounts add more layers. NFS with root_squash maps root to an unprivileged user, so a directory that root owns on the server can deny root on the client. Mount options such as noexec do not affect traversal, but they do produce EACCES when executing a binary from that mount.
For a programmatic check, test permission on each parent rather than only on the leaf:
import os
from pathlib import Path
target = Path("/srv/private/data/report.txt")
for parent in target.parents:
if not os.access(parent, os.X_OK):
print("no search permission:", parent)
The same traversal rules apply to relative paths, so a relative path can fail while the absolute path printed by pwd identifies the same file; see ENOENT and relative paths for how the working directory enters resolution.
Edge cases and distinctions
EACCES is not EPERM. EPERM usually signals an operation restriction that no permission bit can fix, such as changing a file's owner or writing an immutable file. A read-only mount commonly returns EROFS, not EACCES. SELinux and AppArmor can return EACCES even when Unix modes look permissive, so if namei -l shows every component as traversable, check the audit log and the security policy. On Linux, root passes these checks only if at least one execute bit is set on the directory, so a directory with mode 000 is not traversable even by root. When the path contains a symlink, the denial can occur at a component of the link target rather than at a component of the path you passed.
Sources
Revision history
- Published
- Updated
- — Initial publication.