bitlvl
EN

chmod & permissions cheat sheet

The whole permission system fits on one page. Print it, or keep the chmod calculator open for anything interactive.

Fits on one A4 / Letter page in portrait; use “Save as PDF” in the print dialog to keep a copy.

Reading permissions

-rwxr-xr-xtype, owner rwx, group r-x, others r-x
r = 4, w = 2, x = 1add per group → octal digit
rwx r-x r-x= 7 5 5 = 755
d l c b p sdirectory, symlink, char dev, block dev, pipe, socket

Common modes

644files: owner rw, everyone r
755directories, scripts, binaries
600 / 700private file / directory (SSH keys, .env, ~/.ssh)
664 / 775group-writable file / directory
2775shared dir: new files inherit the group (setgid)
1777/tmp: anyone writes, only owners delete (sticky)
4755setuid binary (passwd, sudo)
777almost always wrong

Symbolic chmod

u g o auser (owner), group, others, all
+ - =add, remove, set exactly
chmod u+x fowner may execute
chmod go-w fgroup and others lose write
chmod a=r feveryone read only
chmod u=rwx,g=rx,o= f= 750
chmod -R u=rwX,go=rX dirrecursive; X = execute only for dirs and already-executable files
chmod g+s dirsetgid on a directory
chmod +t dirsticky bit
chmod --reference=a bcopy a's mode to b

Special bits (leading octal digit)

4 setuidrun as the file's owner; shows as s in owner x
2 setgidrun as group; on dirs: inherit group; s in group x
1 stickyin dirs: only owner may delete; t in others x
S / Tcapital = special bit set without execute (usually a mistake)

Ownership

chown user filechange owner (root only)
chown user:group fileowner and group
chown -R www-data: /var/wwwrecursive; empty group = user's login group
chgrp group filegroup only (member can do it)
chown -hchange the symlink itself, not the target

umask

umask 022files 644, dirs 755 (default)
umask 077files 600, dirs 700 (private)
umask 002files 664, dirs 775 (group work)
UMask=0077in a systemd [Service]

Finding and fixing

find . -type f -perm -o+wworld-writable files
find / -perm -4000 -type fsetuid binaries
find . -type d -exec chmod 755 {} +fix dirs only
find . -type f -exec chmod 644 {} +fix files only
stat -c '%a %U %G %n' *octal mode, owner, group, name
ls -ld dirthe directory itself, not its contents

ACLs (when rwx is not enough)

getfacl fileshow; a + in ls -l means one exists
setfacl -m u:alice:rw filegive alice rw
setfacl -m d:g:dev:rwx dirdefault ACL for new files in dir
setfacl -b fileremove all ACLs

Remember

  • Directory x = may enter; r = may list; w = may create/delete entries.
  • Deleting a file needs w on the directory, not on the file.
  • root ignores rwx (but not the execute bit for running).
  • “Permission denied” is often ownership; check ls -l before chmod 777.

Questions

How do I fix a whole web root safely?

find /var/www -type d -exec chmod 755 {} + and find /var/www -type f -exec chmod 644 {} +, then chown -R www-data: /var/www. Never chmod -R 777.