Permissions & ACLs (chmod/chown/setuid)
Why Permissions Matter in Production
Linux permissions are not just about access. They define security boundaries. A single incorrect permission can expose secrets, allow privilege escalation, or break deployments. Production systems must treat permissions as a design decision, not a quick fix.
The Three Layers: User, Group, Others
Every file has three permission scopes:
- User (owner)
- Group
- Others (world)
-rwxr-x---
This means:
- User: read, write, execute
- Group: read, execute
- Others: no access
Numeric (Octal) Mode Explained
Permissions are often written numerically:
chmod 750 file
Breakdown:
- 7 = rwx
- 5 = r-x
- 0 = ---
Production-safe defaults:
- Directories: 750
- Config files: 640
- Secrets: 600
chmod Is Not a Fix Tool
If your solution is “chmod 777”, you are hiding a design mistake. Fix ownership, not permissions.
Ownership Strategy
chown myapp:myapp /srv/myapp
Correct ownership reduces the need for overly permissive modes.
setuid and setgid
Special permission bits change execution behavior.
setuid (4000)
Executable runs with file owner permissions. Example:
chmod 4755 binary
Be extremely cautious. Misuse can cause privilege escalation.
setgid (2000)
When applied to directories, new files inherit the directory group. This is useful in deploy groups:
chmod 2750 /srv/myapp
Sticky Bit (1000)
Used mostly on shared directories like /tmp.
chmod 1777 /shared
Users can only delete their own files.
When Basic Permissions Are Not Enough: ACLs
ACL (Access Control Lists) allow more granular permissions. Example:
setfacl -m u:deploy:rwx /srv/myapp getfacl /srv/myapp
ACLs are useful when:
- Multiple teams need selective access
- Deploy user needs write access but not ownership
- You cannot restructure group hierarchy easily
Common Production Mistakes
- World-readable .env files
- Secrets with 644 permissions
- Log files writable by everyone
- Shared SSH keys across users
How to Audit Permissions Quickly
find /srv -type f -perm -002 find / -perm -4000 2>/dev/null ls -lR /srv/myapp
Mental Model
Permissions define containment. If an attacker gains access to one service user, proper permissions prevent lateral movement.
Production Checklist
- No 777 anywhere
- No world-readable secrets
- Service directories owned by service user
- setuid binaries audited
- Sticky bit correctly used on shared dirs