The Doorway Bit: Why a Readable Linux Directory Can Still Refuse Entry
A directory displays r-- in its permissions. It is readable, so opening files inside it should work—right? Linux says otherwise. For directories, the familiar permission letters describe different operations than they
A directory displays r-- in its permissions. It is readable, so opening files inside it should work—right?
Linux says otherwise.
For directories, the familiar permission letters describe different operations than they do for ordinary files. Read permission reveals the directory’s list of names. Execute permission allows those names to be used as paths.
That distinction creates a strange-looking situation: a user may see that report.txt exists yet be unable to read it.
Two separate abilities
Consider this directory:
dr--r--r-- reports/
-rw-r--r-- reports/report.txt
Everyone has read permission on reports/, but nobody has execute permission. A non-owner may be able to run:
ls reports
and see:
report.txt
But this fails:
cat reports/report.txt
The file itself is world-readable. The failure occurs before Linux evaluates that file permission: the kernel cannot traverse reports/ to reach it.
Directory permissions govern these capabilities:
| Permission | Meaning on a directory |
|---|---|
r |
List the names stored in the directory |
w |
Modify directory entries |
x |
Search or traverse the directory using a name |
The word “execute” is misleading here. Linux is not executing the directory. The bit acts more like permission to pass through a doorway.
Knowing a name is not enough
The reverse combination is also possible:
d--x--x--x reports/
Without read permission, ls reports cannot enumerate the directory. Yet a user who already knows the exact filename may access it:
cat reports/report.txt
That succeeds if every directory in the path grants traversal and the file grants read access.
This resembles a hallway with no directory sign: occupants cannot inspect the list of rooms, but they can enter room 204 if they already know its number and have permission to open its door.
Every path component matters
For this path:
/srv/finance/quarterly/report.txt
Linux must traverse /, srv, finance, and quarterly. Missing execute permission on any one of those directories blocks access, regardless of the final file’s mode.
That is why a diagnostic such as this is useful:
namei -l /srv/finance/quarterly/report.txt
It exposes permissions component by component, making the locked doorway visible.
The corrected claim
Directory read permission does not grant access to files inside the directory. It permits listing names. Accessing a named entry requires execute permission on that directory—and on every directory crossed to reach it—followed by whatever permissions the final file itself requires.
When ls can see a file but cat reports “Permission denied,” the file is not necessarily the problem. Check the doorways.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.