Lesson 11 of 14 · 20m
Permissions, ownership, and umask without chmod 777
The three-slot model, setgid shared dirs, umask per layer, and setfacl for the cases POSIX can't express.
When a deploy dies with EACCES, the fix most people reach for is chmod -R 777 — which doesn't fix the problem, it deletes the problem, along with the only thing standing between "web process can read uploads" and "web process can execute whatever got uploaded." Permissions are a three-slot model plus three special bits, and nearly every incident involving them traces to someone not checking which slot was actually blocking.
The bits
rwx per slot — owner, group, other. On directories the bits mean different things: read lists entries, write creates and deletes entries, execute traverses. A directory can be listable but not traversable, which produces exactly the confusing half-permissions that make people give up and 777.
chmod takes octal (640, 2770) or symbolic (u+r, g-w, o=); chown sets owner:group. For shared directories, the mechanism people don't know exists is setgid: chmod 2770 /srv/app makes every file created inside inherit the group, so deploy members can write each other's files without a permanent fight.
Setuid (u+s, 4xxx) runs the binary with the file owner's privileges — that's the entire mechanism behind sudo and passwd, and also why a setuid binary that shells out is a privilege-escalation finding. find / -xdev -perm /6000 -type f lists every setuid+setgid file; baseline it once so a new one stands out. The sticky bit (+t, 1xxx) on shared dirs like /tmp means only a file's owner can delete it.
The permissions already protecting you are worth memorizing as a baseline: /etc/shadow is root:shadow 640, /etc/ssh/sshd_config is root:root 644, private keys under ~/.ssh/ are 600. If a package or a previous admin left any of those wider — a world-readable shadow is a find-it-in-audit classic — tighten it and ask why it was loosened.
umask: what things are born with
Files aren't created at 777 and locked down; they're created at 0666 & ~umask for files and 0777 & ~umask for directories. The default umask 022 yields 644/755 — world-readable everything. On a multi-service box or anywhere secrets land, umask 027 (group reads, other gets nothing) or 077 (owner only) is the correct default. Set it in the shell profile and the systemd unit (UMask=) and the app config, because each layer can silently widen it back.
When three slots aren't enough: ACLs
Two groups needing different access to one tree is where POSIX permissions end. setfacl -m g:qa:rx /srv/app/releases grants qa their own entry; getfacl shows the real picture — the + at the end of ls -l output is your hint that ACLs exist. Default ACLs (setfacl -d -m g:qa:rx ...) propagate to new files the way setgid propagates group ownership; combine them for shared trees.
Try this
groupadd deploy && useradd -m -G deploy alice && useradd -m -G deploy bob
mkdir -p /srv/shared && chgrp deploy /srv/shared && chmod 2770 /srv/shared
# as alice: touch /srv/shared/notes — check the group is deploy, not alice
setfacl -m g:qa:rx /srv/shared # qa reads, deploy writes
getfacl /srv/shared
find / -xdev -perm /6000 -type f 2>/dev/null # baseline your setuid/setgid setPitfalls
chmod -Rblanket fixes: you just made every file in a config tree executable — and on a webroot, writable by every local process.- Recursive
chownon paths containing symlinks follows them into places you didn't mean (chown -hfor links). ~/.sshat 755 orauthorized_keysowned by root: sshd ignores unsafe key files and the failure looks like "key rejected."- umask set in the shell but not the unit: the daemon's files come out with different permissions than the operator's.
- NFS
root_squash: remote root maps tonobody; permissions look right and still fail.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Self-Host OpenClaw: VPS Setup to Production (2026)
Self-host OpenClaw from zero to production. Server provisioning, SSH lockdown, Docker, reverse proxy, Fail2ban, performance tuning, and full backup strategy in one guide.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.
Red Hat Called This Bug a 5.9. Two Weeks Later It Was a 9.8.
CVE-2026-98432 is a use-after-free in the IPv4 TCP handshake, reachable by anybody who can reach a listening port, sitting in the kernel since 4.4. Red Hat scored it 5.9 moderate and deferred the fix. Then 8.1. Then 9.8.
Self-Hosting Vaultwarden Without Trusting the Defaults
Vaultwarden gives you a Bitwarden-compatible password server in one container and about ten minutes. The defaults that make that possible leave org creation open, audit logging off, accounts on PBKDF2, and a rate limiter that trusts a header anyone can set.