devutils/ATFQ/book ATFQ git

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.
  • r read, w write, x execute. On a folder, x means "may enter".
  • In octal, r=4, w=2, x=1, added per set: 644 is rw-r--r--, 755 is rwxr-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

alice@laptopexample
$ 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

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.

Commands
chmod chown umask
See also
15.2 setuid, setgid and sticky bit
15.3 sudo and groups