Lesson 7 of 14 · 20m
Permissions, setuid, and sudo
Nine mode bits plus setuid explain sudo itself, why 777 is a shell waiting to happen, and why `/etc/sudoers` is only touched through `visudo`.
chmod 777 is the answer juniors reach for, and it "works" the way leaving your house unlocked works. -rwxrwxrwx on a file means every local user can write executable content into it; on a webroot, that's a shell anyone on the box can deliver through the web server. The permission model isn't arbitrary ceremony — nine bits decide who may read, write, and enter, and learning them once ends a whole class of confused afternoons.
The bits
Three triples — owner, group, other — each rwx worth 4+2+1:
chmod 644 file— owner writes, everyone reads. Default for files.chmod 755 dir— owner writes, everyone enters and lists. Default for directories and scripts.chmod 600 file— owner only. Private keys, secrets.chmod u+x,chmod go-w— symbolic form when you're adjusting, not setting.
Directories get the interesting semantics: r lists entries, w creates and deletes entries, x lets you traverse — open a file whose name you already know. A 711 directory denies ls but permits cat dir/known-file. Write permission on a directory — not on the file — controls deletion, which is why rm can remove a file you can't edit.
umask sets the bits new files don't get: umask 022 produces 644 files and 755 dirs. When a new file comes out 664, the editor didn't do it — the umask did.
Ownership and groups
chown user:group file, chgrp, and id to see your groups. usermod -aG docker user adds a supplementary group — the -a is load-bearing. usermod -G docker user replaces the entire supplementary list, the classic way to remove yourself from sudo/wheel while trying to add docker.
chmod g+s on a directory means new files inherit the directory's group — the shared-workdir trick that keeps a team's files group-writable without anyone running chgrp by hand.
setuid and the sticky bit
ls -l "$(which sudo)" shows -rwsr-xr-x. 1 root root. That s — the setuid bit — is the whole mechanism behind sudo: the binary runs as its owner (root) no matter who invokes it. It's also attack surface: CVE-2021-3156, "Baron Samedit" (Qualys, January 2021), was a heap overflow in sudo's argument parsing, present since 2011, turning any local user into root. find / -perm -4000 -type f lists every setuid binary on the box — run it on a system you maintain and explain each line.
/tmp is drwxrwxrwt: the t (sticky bit) means anyone can create files there but only the owner can delete their own. Without it, any user could delete another's temp files.
sudo
sudo reads /etc/sudoers to decide what you're allowed to run — and that file is edited only through visudo, which syntax-checks on save. A broken sudoers locks every sudoer out; that's the footgun visudo was invented for. The line %sudo ALL=(ALL:ALL) ALL means: group sudo, any host, as any user and group.
sudo -l— what you may run.sudo -i— root login shell.sudo -u postgres psql— run as a non-root user; the underused flag that makes service accounts workable.sudoedit file— edit a root-owned file with your editor via a temp copy; the answer that's notchmod 666.sudo -k— drop the cached credentials early (thetimestamp_timeoutdefault is 5 minutes upstream; Debian ships 15).NOPASSWD:in sudoers removes the prompt for automation — and removes the only thing standing between a compromised service account and root. Know what it costs.
Practice
- Least permission that works:
644/755/600, group access before world access, a shared group before777. visudofor sudoers,sudo -ufor service accounts,sudoeditfor root files.- Audit
find / -perm -4000 -type fonce per box; everything there is root code reachable by a local user.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
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-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.
Self-Hosting Prometheus and Grafana: Infrastructure Monitoring That Actually Works
Build a production-grade monitoring stack with Prometheus and Grafana from scratch. Covers architecture, Docker Compose deployment, Node Exporter, alerting with Alertmanager, PromQL from basics to advanced, pre-built dashboards, and everything SudoSecurity uses to monitor its own infrastructure.
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.