Linux Labs

Users, permissions, and processes / Stage 4 of 13

A shared directory: setgid, sticky, and umask

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · on a machine · 6 min

The group of a new file

A new file's group is chosen by the process that creates it. A directory can change that rule.

The owner of a new file is the process's user, and its group is the process's primary group. Ubuntu gives every user a personal group with the same name, so alice's primary group is alice. That is how plan.txt got the group alice even though it sat in the devs group's directory. bob is not in the alice group, so the others triple applied to him: r--.

The setgid bit on a directory changes the rule: a new file gets the directory's group. The bit sits in the group's x position as the letter s:

text
drwxrwsr-x 2 root devs 4096 Oct 20 05:27 /srv/team

chmod g+s directory sets it. In numeric form it is a 2 in front of the usual three digits: chmod 2775 directory. A subdirectory created inside gets both the directory's group and the bit itself. Files that were already in the directory keep their group: chown :devs file changes it.

Exercise · do it

Give new files the directory's group

In /srv/team, make new files get the devs group, whoever creates them. Keep the directory's owner, group, and rwxrwxr-x as they are.

Sign in and start The machine is available after signing in

Goals · 0 of 1

  • Pass the devs group on to new files not done yet

Step goals

0 of 1
  • Pass the devs group on to new files — not done yet
Ubuntu 24.04

Step goals

0 of 1
  • Pass the devs group on to new files — not done yet
Loading…