Latticework

Command Palette

Search for a command to run...

Linux

Permissions

16 min

Explanation

Every file has three permission triplets — owner, group, and other (everyone else) — each made of read (r), write (w), and execute (x) bits. chmod changes them, either as a 3-digit octal number (each digit 0-7 encodes one triplet: 4=read, 2=write, 1=execute, added together — 6 = read+write, 7 = read+write+execute) or symbolically (chmod +x file adds execute for everyone, chmod -x file removes it). ls -l shows the resulting permission string as ten characters: a leading d/- for directory-vs-file, then the three rwx triplets.

touch script.sh
chmod 600 script.sh
ls -l
# -rw-------  script.sh
chmod +x script.sh
ls -l
# -rwx--x--x  script.sh
Try it

644 (rw-r--r--) is the typical default for a plain file: the owner can edit it, everyone else can only read it. 700 (rwx------) locks it down to the owner alone.

Loading editor…
Exercise

Create a file `deploy.sh`. First restrict it to `600` (read/write for the owner only, nothing for anyone else), then separately make it executable for everyone by adding the execute bit with `chmod +x`.

Quiz

A file's permissions are shown as `rwxr-xr-x`. What do the three groups represent, left to right?

Checkpoint

You can read and change file permissions with chmod, using both octal and symbolic (+x/-x) modes.