Skip to main content
Linux

chmod explained: Linux file permissions without the cargo cult

Read ownership and the existing mode before changing permissions; use the least access your process needs instead of reaching for 777.

Thien Nguyen
By Thien Nguyen
Updated July 21, 2026 · 2 min read

chmod 777 does not solve a permissions problem; it makes every local account and service a potential writer. Start with ls -l, identify the process user, then change the narrowest bit that makes the access legitimate.

Read the mode before changing it

-rw-r----- 1 app deploy 840 Jul 20 09:10 .env

The three triplets are owner, group, and other. r is 4, w is 2, and x is 1; the line above is 640: the owner can read/write, the group can read, and everyone else gets nothing.

TargetTypical modeWhy
Application secret600Only its owner should read it
Static public file644Process can write; web server can read
Executable script755Everyone can run it, only owner can alter it
Private directory700No listing or traversal for others

Directories are not files

On a directory, x permits traversal. A user may be able to read a directory's names but cannot open a known file without execute permission on every parent directory. That is why blindly adding read does not fix a “Permission denied” path error.

namei -l /srv/app/config/.env
stat -c '%A %a %U:%G %n' /srv/app/config/.env

namei exposes the permissions of each path component; it saves a lot of guesswork with mounted volumes and service accounts.

Fix ownership when ownership is wrong. Running chmod -R 777 on a deploy directory hides the real problem and can turn a compromised low-privilege process into a code writer.

Prefer symbolic changes for small edits

chmod u+x deploy.sh     # owner may execute
chmod g-r secrets.txt   # group may no longer read
chmod o= public.txt     # remove all access for others

Numeric modes are great when declaring a complete policy; symbolic modes are safer when adjusting one bit. If ACLs, SELinux, or a network filesystem are involved, inspect those too—classic mode bits may not be the deciding rule.

Cover photo by Pixabay on Pexels.

References

Primary documentation and specifications checked when this article was last updated.

LinuxSecurityCLI

Related articles

All articles