C.W.K.
Stream
Lesson 12 of 12 · published

File Permissions: rwx, chmod, chown

~15 min · chmod, chown, permissions, umask

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

The 9 bits that decide everything

Every Unix file has three sets of three permission bits: read, write, execute — for owner, group, others. ls -l shows them as rwxr-xr--: owner has all three, group has read+execute, others only read.

Symbolic chmod

  • chmod u+x file — add execute for owner
  • chmod g-w file — remove write from group
  • chmod o= file — remove all permissions for others
  • chmod a+r file — read for all (a = u+g+o)

Numeric chmod

Each rwx is one octal digit. r=4, w=2, x=1. Add them: rwx=7, rw-=6, r-x=5, r--=4. Three digits = owner/group/others.

  • chmod 755 script.sh — rwxr-xr-x. Standard for executables.
  • chmod 644 file.txt — rw-r--r--. Standard for regular files.
  • chmod 600 ~/.ssh/id_ed25519 — rw-------. Required for SSH private keys.
  • chmod 700 ~/.ssh — rwx------. SSH dir.

Directories

On a directory, x means "can enter" (cd into), r means "can list contents," w means "can add/remove entries." That's why scripts often need chmod 755 on a dir, not 644.

chown — change owner

chown alice file changes owner to alice. chown alice:staff file sets owner and group. -R for recursive. Often requires sudo because you usually can't give your files away to other users.

umask — default permissions

When you create a file, the kernel uses 0666 & ~umask; for directories 0777 & ~umask. The default 022 umask gives 644 files and 755 dirs. umask 077 makes new files readable only by you — useful in dotfiles where private data lives.

Code

Common chmod patterns·bash
chmod +x script.sh                # add x for everyone
chmod 755 script.sh               # rwxr-xr-x
chmod 644 README.md               # rw-r--r--
chmod 600 ~/.ssh/id_ed25519       # SSH key — must be 600
chmod 700 ~/.ssh                  # SSH dir — must be 700
chmod -R u+rwX,go-w project/      # recursive, smart X for dirs
Decode rwx to octal·text
rwx = 4+2+1 = 7
rw- = 4+2   = 6
r-x = 4+1   = 5
r-- = 4     = 4
rwxr-xr-x = 755
rw-r--r-- = 644

External links

Exercise

Create an empty script.sh, run ls -l script.sh (should be 644). Make it executable: chmod +x script.sh, observe the new mode. Then chmod 755 script.sh and confirm. Now chmod 600 ~/.ssh/id_* if you have SSH keys — many tutorials forget this and ssh quietly fails.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.