Linux File Permissions and Ownership
- Description: How Unix file permissions and ownership work — the
rwxmode triad, octal notation,chmod/chown/chgrpusage, special bits (setuid, setgid, sticky),umaskdefaults, and a brief pointer to POSIX ACLs. - My Notion Note ID: K2B-3-3
- Created: 2020-06-03
- Updated: 2026-05-19
- License: Reuse is very welcome. Please credit Yu Zhang and link back to the original on yuzhang.io
Table of Contents
- 1. The Permission Model
- 2. Reading
ls -lOutput - 3.
chmod— Symbolic Mode - 4.
chmod— Octal Mode - 5. Special Bits: setuid, setgid, sticky
- 6.
chownandchgrp - 7.
umask— Default Permissions - 8. ACLs (Brief)
- 9. References
1. The Permission Model
- Three identity classes:
- u (user) — the file's owner
- g (group) — the file's group
- o (other) — everyone else
- a (all) — shorthand for
ugo
- Three permissions per class:
- r read — list directory entries, or read file content
- w write — modify file content; for a directory, create/delete/rename entries
- x execute — run the file as a program; for a directory, traverse into it (look up entries by name)
- Permissions on directories have surprising semantics:
rwithoutx→ you canlsthe dir but cannotstator read any file inside.xwithoutr→ you cancdin and access named files but cannotls.wrequiresxto be meaningful — you need traversal to actually create or delete entries.
2. Reading ls -l Output
-rwxr-xr-- 1 alice devs 4096 May 10 12:34 build.sh
drwxr-x--- 3 alice devs 128 May 10 12:35 src
lrwxrwxrwx 1 alice devs 11 May 10 12:36 link -> build.sh
- First character — file type:
-regular,ddirectory,lsymlink,c/bchar/block device,pnamed pipe,ssocket. - Next nine — three rwx triads for
u,g,o. - Owner / group columns — names from
/etc/passwdand/etc/group. - Symlinks are usually shown as
lrwxrwxrwx— symlink mode is ignored; permissions of the target are what matter.
3. chmod — Symbolic Mode
chmod [OPTION]... MODE FILE...- Symbolic form:
[ugoa...][+-=][rwxX]...[,...]- Class:
u,g,o,a(default if you omit it isamasked byumask). - Operator:
+add,-remove,=set exactly. - Perm:
r,w,x. PlusX— "execute only if it's a directory or already has anyxbit set" — perfect forchmod -R u+rwX,go+rXon a mixed tree.
- Class:
- Examples:
chmod u+x build.sh— make executable for owner only.chmod go-w secrets.txt— drop write for group and other.chmod a=r README— exactlyr--r--r--for everyone.chmod u+rwx,g+rx,o= dir— combine multiple clauses with commas.
- Useful options:
-R, --recursive— apply to a tree. Combine withXto keep dir traversal sensible.--reference=FILE— copy permissions from another file.-v— print every change;-c— print only actual changes.
4. chmod — Octal Mode
- Four octal digits:
SUGO, whereSis the special-bits digit (often0and omitted) andU,G,Oare the rwx triads. - Per-triad sum:
r=4,w=2,x=1.7 = rwx,6 = rw-,5 = r-x,4 = r--,0 = ---.
- Common modes worth memorizing:
| Octal | Symbolic | Typical use |
|---|---|---|
644 |
rw-r--r-- |
regular file readable by all |
600 |
rw------- |
private file (SSH keys, .netrc) |
755 |
rwxr-xr-x |
executable / world-readable dir |
750 |
rwxr-x--- |
group-shared executable / dir |
700 |
rwx------ |
private dir (~/.ssh) |
4755 |
rwsr-xr-x |
setuid root binary (/usr/bin/sudo) |
2775 |
rwxrwsr-x |
setgid dir for shared projects |
1777 |
rwxrwxrwt |
sticky world-writable dir (/tmp) |
5. Special Bits: setuid, setgid, sticky
The leading digit in the 4-digit octal (S = setuid*4 + setgid*2 + sticky*1):
- setuid (4) on an executable → process runs as the file's owner regardless of who launched it. The classic example is
passwd: the program needs to edit/etc/shadow, which is root-only, so it's4755and owned by root. Setuid on shell scripts is ignored on Linux for security reasons. - setgid (2):
- On an executable → runs with the file's group identity.
- On a directory → new files inside inherit the directory's group, not the creator's primary group. This is how shared project directories stay consistent.
- sticky (1) on a directory → only a file's owner (or root) may delete or rename it, even if the directory is world-writable.
/tmpis the canonical case (1777). - Symbolically:
chmod u+s,chmod g+s,chmod +t. Visible inls -lass(in place ofx) andt(sticky in the world triad). CapitalS/Tmean "the special bit is set but the underlyingxis not" — usually a mistake.
6. chown and chgrp
chown [OPTION]... [OWNER][:[GROUP]] FILE...— change owner, group, or both.chown alice file— owner only.chown alice:devs file— owner and group.chown :devs file— group only (equivalent tochgrp devs file).chown alice: file— owner alice, group set to alice's primary group.
chgrp [OPTION]... GROUP FILE...— change group only. Subset ofchown.- Options shared by both:
-R, --recursive— apply to a tree.-h— operate on the symlink itself, not its target. Default is to follow.--reference=FILE— copy ownership from another file.--from=CURRENT_OWNER[:CURRENT_GROUP]— only change if the current owner/group matches (safe rewrites).
- Only root can change a file's owner. Non-root can only change a file's group, and only to a group the user belongs to.
7. umask — Default Permissions
umaskis the bits that are turned off when new files and directories are created. Default mode would be666for files and777for directories; the actual mode is(default) & ~umask.- Common umasks:
022→ files644, dirs755. Most distros' default.002→ files664, dirs775. Group-writable; for shared dev machines.077→ files600, dirs700. Privacy-conscious.
- Set in
~/.bashrc/~/.zshrc//etc/profilefor persistent change.umask 022to inspect,umask -Sto print symbolically.
8. ACLs (Brief)
When the ugo triad isn't enough (multiple groups need different access, or per-user grants), POSIX ACLs give per-principal entries.
- Check:
getfacl FILE— shows the ACL, including the standardugobits. - Set:
setfacl -m u:bob:r file(give bob read),setfacl -m g:auditors:rx dir. - Mask entry caps the maximum permission grantable to named users/groups.
- Default ACLs on a directory (
setfacl -d -m ...) act like a stickiersetgid: new entries inherit the ACL. ls -lshows a trailing+in the mode field when a file has an ACL:-rw-r--r--+.- Not all filesystems support ACLs — most modern Linux setups (ext4, xfs, btrfs) do; FAT/exFAT do not.
9. References
man 1 chmod,man 1 chown,man 1 chgrp,man 1 umask,man 5 acl- GNU coreutils manual —
info coreutils→ "File permissions" - POSIX ACL —
man getfacl,man setfacl