Pikkola Chmod Studio, tool No. 33

Seven characters decide who can do what.

Tick the bits, or paste a mode you found in a config file, and read it back as octal, symbolic and umask. The same page writes the chmod, find and chown lines you need and copies them. It all runs in this tab, so no path, user name or file mode leaves it.

12
bits
3
layers
0
uploads
what ls prints
$ ls -l deploy.sh
-rwsr-xr-x  1 deploy deploy  412 Nov 19 08:14 deploy.sh
drwxr-xr-x  4 deploy deploy 4096 Nov 19 08:14 public/
what chmod takes
$ chmod 4755 deploy.sh
$ chmod u=rwxs,g=rx,o=rx deploy.sh
4755  # or  u=rwxs,g=rx,o=rx

The builder

Tick a box, read the mode

Owner, group and other each carry three bits, and three more bits ride on top of them. Every change is written three ways at once, so a mode you type and a box you tick stay in step.

Entry type
Octal
755
Symbolic
-rwxr-xr-x
Clean

Nothing is open to other accounts

Only the owner, and the group where you allowed it, can touch this.

Permission matrix

4 · 2 · 1
Read4 Write2 Execute1 Octal
Owner 7
Group 5
Other 5
Special bits
Presets

What this mode allows

Owner
read, write, run
Group
read, run
Other
read, run

A directory is not a file.

Umask, the other direction

A umask is subtracted from 666 for a new file and from 777 for a new directory.

New files 644
New directories 755

Nothing leaves the tab

No request, no account, no storage.

The command

Lines you can paste

chmod and chown follow the mode above.

chmod

Mode form
chmod 755 ./public

The mode is absolute.

find -exec

find ./public -type f -exec chmod 644 {} +

Changing a tree takes two passes.

chown

chown www-data:www-data ./public

chown changes who owns a file.

How the notation works

Digits are arithmetic, letters are the same bits spelled out

One permission digit is three bits: 4 for read on the left, 2 for write in the middle, 1 for execute on the right.

One digit, eight ways

Digit Bits Means
7rwxread, write, run
6rw-read and write
5r-xread and run
4r--read only
3-wxwrite and run
2-w-write only
1--xrun only
0---nothing

The fourth digit

A leading digit carries the special bits: 4 setuid, 2 setgid, 1 sticky.

One digit holds three bits

4 is read, 2 is write, 1 is execute.

Letters are the same bits, spelled out

-rwxr-xr-x is one character for the entry type and nine for the bits.

Directories read differently

In a directory, r lists names, x lets you enter, and w lets you create and delete.

Questions

What does 755 mean?

The owner may read, write and execute.

Why is 644 written rw-r--r--?

6 is 4 plus 2, so rw.

What does umask 022 do?

It removes the group and other write bit from everything you create.

Is chmod -R 777 ever the right answer?

Almost never.

What is the difference between chmod and chown?

chmod sets what the owner may do; chown sets who the owner is.

Does this work on macOS, or on Windows?

macOS and Linux use the same notation.