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 1 of 7 · on a machine · 5 min

The team's shared folder

What you will learn

  • Set up a shared directory where new files get the team's group.
  • Explain a new file's mode by the umask and find where the mask is set.
  • Protect files in a shared directory from deletion by others with the sticky bit.

The devs team, alice and bob, keeps shared files in /srv/team. The directory belongs to the devs group, and the group may write to it. Watch the two of them at work: alice puts a plan there, bob tries to append to it and then tidies the directory up.

The commands for alice and bob run through sudo -u, as in the previous lesson. Start creates both accounts and the directory.

Exercise · look

Watch the shared directory at work

Run the commands in order: alice creates plan.txt in /srv/team, you look at ls -l, bob tries to append to the file and then deletes it.

First, predict

Which group will ls -l show for plan.txt?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

Why could bob not append to plan.txt even though he is in the devs group?

  • tee -a appends to any file where the process has w. bob has none: the file's group is alice, and he got the r-- triple.

  • sudo -u starts a new process and reads the groups again: sudo -u bob id shows devs.

  • bob can write to the directory through the devs group: rm -fv deleted plan.txt, and deleting changes the directory.

plan.txt is in the group alice, which bob does not belong to, so the others triple r-- applied to him.

Ubuntu 24.04
Loading…