chmod
chmod 755 ./public
The mode is absolute.
Pikkola Chmod Studio, tool No. 33
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.
$ 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/
$ chmod 4755 deploy.sh $ chmod u=rwxs,g=rx,o=rx deploy.sh 4755 # or u=rwxs,g=rx,o=rx
The builder
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.
-rwxr-xr-x
Nothing is open to other accounts
Only the owner, and the group where you allowed it, can touch this.
A directory is not a file.
A umask is subtracted from 666 for a new file and from 777 for a new directory.
No request, no account, no storage.
The command
chmod and chown follow the mode above.
chmod 755 ./public
The mode is absolute.
find ./public -type f -exec chmod 644 {} +
Changing a tree takes two passes.
chown www-data:www-data ./public
chown changes who owns a file.
How the notation works
One permission digit is three bits: 4 for read on the left, 2 for write in the middle, 1 for execute on the right.
| Digit | Bits | Means |
|---|---|---|
| 7 | rwx | read, write, run |
| 6 | rw- | read and write |
| 5 | r-x | read and run |
| 4 | r-- | read only |
| 3 | -wx | write and run |
| 2 | -w- | write only |
| 1 | --x | run only |
| 0 | --- | nothing |
A leading digit carries the special bits: 4 setuid, 2 setgid, 1 sticky.
4 is read, 2 is write, 1 is execute.
-rwxr-xr-x is one character for the entry type and nine for the bits.
In a directory, r lists names, x lets you enter, and w lets you create and delete.
The owner may read, write and execute.
6 is 4 plus 2, so rw.
It removes the group and other write bit from everything you create.
Almost never.
chmod sets what the owner may do; chown sets who the owner is.
macOS and Linux use the same notation.