Part II · Your system
15.1 rwx, octal and umask
alsopermissionsfile permissionschmodumaskrwxoctalpermission denied
TL;DR
- Every file has an owner, a group, and three sets of rights: for the owner, for the group, for everyone else.
rread,wwrite,xexecute. On a folder,xmeans "may enter".- In octal, r=4, w=2, x=1, added per set:
644isrw-r--r--,755isrwxr-xr-x. - The umask removes rights from new files: with
022, files get 644 and folders 755.
ls -l notes.txt
chmod 640 notes.txt # owner rw, group r, others nothing
chmod u+x deploy.sh # let the owner run it
On your machine
$ atfq 15.1 User alice (uid 1000, gid 1000) Groups alice, wheel, docker, 4242 Admin member of wheel: the group sudo usually trusts Umask 0022: new files 644 (rw-r--r--), new folders 755
An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.
Pitfalls
- On a folder,
rlists the names andxlets you open what's inside: withrbut nox, you see names you can't open. - Deleting a file depends on the folder's
w, not on the file's rights. ⚠ chmod -R 777"fixes" an error by letting everyone write everything. Fix the owner or the group instead.- Root ignores read and write rights, but still needs some
xbit to run a file. - The umask never adds rights: new files start from 666, folders from 777, so a new file is never executable.
Deep dive 2 questions
Why octal?
Each set of rights is three bits, and one octal digit is exactly three
bits, so 750 reads as owner 7 (rwx), group 5 (r-x), others 0. A fourth
digit in front holds the setuid, setgid and sticky bits (see 15.2):
chmod 2775 shared/.
Where does the umask come from?
A process inherits it from its parent. Your login sets it, from
/etc/login.defs or a shell startup file, and you can change it for the
current shell with umask 077. systemd services use the UMask= setting
of their unit, 0022 by default.
Common values are 022 (others can read) and 077 (private). Some distros use 002 for regular users, since each user has a private group of their own.