📋 Cheat Sheets

chmod Cheat Sheet — Linux File Permissions Explained


Click any item to expand the explanation and examples.

📐 The Basics

Reading permissions (ls -l) basics
$ ls -l
-rwxr-xr-- 1 alice staff 4096 Mar 14 10:00 script.sh
│├──┤├──┤├──┤
│ │   │   └── Others: read only
│ │   └────── Group: read + execute
│ └────────── Owner: read + write + execute
└──────────── File type (- = file, d = directory, l = symlink)

Permission letters:

r = read (4)

w = write (2)

x = execute (1)

- = none (0)

Numeric (octal) mode basics
# Each digit = owner, group, others
# r=4, w=2, x=1, add them up

chmod 755 file # rwxr-xr-x (owner: all, group: read+exec, others: read+exec) chmod 644 file # rw-r—r— (owner: read+write, group: read, others: read) chmod 700 file # rwx------ (owner: all, nobody else) chmod 600 file # rw------- (owner: read+write, nobody else) chmod 777 file # rwxrwxrwx (everyone: all — usually bad!) chmod 000 file # ---------- (nobody can do anything)

How to calculate:

rwx = 4+2+1 = 7

rw- = 4+2+0 = 6

r-x = 4+0+1 = 5

r— = 4+0+0 = 4

--- = 0+0+0 = 0

Symbolic mode basics
# Who: u=owner, g=group, o=others, a=all
# Action: +=add, -=remove, ==set exactly
# Permission: r=read, w=write, x=execute

chmod u+x file # Add execute for owner chmod g+rw file # Add read+write for group chmod o-w file # Remove write for others chmod a+r file # Add read for everyone chmod u=rwx,g=rx,o=r file # Set exactly

Common patterns

chmod +x script.sh # Make executable (for everyone) chmod -x script.sh # Remove executable

📋 Common Permission Patterns

Files common
chmod 644 file.txt     # rw-r--r--  Normal file (owner writes, everyone reads)
chmod 600 secret.key   # rw-------  Private file (owner only)
chmod 755 script.sh    # rwxr-xr-x  Executable script
chmod 700 script.sh    # rwx------  Private executable
chmod 666 shared.txt   # rw-rw-rw-  Everyone can read/write (rare)
Directories common
chmod 755 mydir/       # rwxr-xr-x  Normal directory
chmod 700 private/     # rwx------  Private directory
chmod 750 team/        # rwxr-x---  Owner + group can access

For directories:

r = list contents (ls)

w = create/delete files inside

x = enter the directory (cd)

SSH files common
SSH is strict about permissions. Wrong permissions = silent failure.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519        # Private key
chmod 644 ~/.ssh/id_ed25519.pub    # Public key
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/authorized_keys
See also: Git permission denied fix

🔧 Recursive & Ownership

chmod -R and chown advanced
# Recursive (apply to all files and subdirectories)
chmod -R 755 mydir/

Better: different permissions for files vs directories

find mydir/ -type f -exec chmod 644 {} + # Files: 644 find mydir/ -type d -exec chmod 755 {} + # Dirs: 755

Change ownership

chown alice file.txt # Change owner chown alice:staff file.txt # Change owner and group chown -R alice:staff mydir/ # Recursive

Change group only

chgrp staff file.txt