Skip to content

Practice: Users and Basic Permissions

Module
Users and Basic Permissions
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (lab container), GNU Bash 5.2.21
Prerequisites
On this page

A batch note is ready for a teammate, but its ownership and permissions still describe a personal file. The handoff also needs an administrator-owned receipt. Your evidence must show who can use each resource, including an intentional failure caused by a parent directory.

This practice combines B11.1–B11.5. Use the lessons and manuals as needed. Report the account doing each operation, the relevant permission field, and the actual result.

Finish Identity and groups through Using sudo and su. Complete the earlier account resets so sam and team are absent. Keep your B04 lab directory.

Use a disposable lab VM or container. These account names belong only to this exercise; do not remove or reuse an unrelated account. The setup authenticates with your own lab account’s password. No password is assigned to sam.

Terminal window
mkdir -p ~/lab/b11/practice/gate
cd ~/lab/b11/practice
sudo useradd -m -s /bin/bash sam
sudo groupadd team
sudo usermod -aG team sam
sudo usermod -aG team learner
printf 'Batch 7 ready\n' > handoff.txt
printf 'Parent check\n' > gate/note.txt
chmod 644 handoff.txt gate/note.txt
chmod 700 gate
sudo mkdir admin
sudo touch admin/receipt.txt
sudo chmod 755 admin
sudo chmod 644 admin/receipt.txt

Use your VM account name instead of learner if it differs. Stay in this original shell to retain the group-membership comparison. Both files are synthetic disposable inputs. The protected receipt starts empty. Use Reset this lesson before repeating the setup.

Reach these six goals:

  1. Record the current account, primary group, and supplementary groups. Compare the running identity with the configured learner account. Decode the initial file type and all three permission fields of handoff.txt and gate.
  2. Restrict the handoff to owner read/write and group read, with no other access. Demonstrate equivalent symbolic and numeric modes. Assign owning group team; verify each transition. Test reads as the owner, teammate sam, and unrelated account nobody.
  3. Temporarily remove only the owner’s search permission from gate. Establish that its existing readable note becomes unreachable through that path. Restore that permission and prove the note can be read again.
  4. Transfer ownership of the handoff to sam while retaining group team and mode 640. Inspect the result. Compare a read by the unchanged learner shell with one by a freshly started learner process.
  5. Run a bounded login-environment command as sam, then use su to authenticate learner and report learner’s primary group. Explain whose password su requests and why sam does not need a password for the sudo test.
  6. Reauthenticate sudo, demonstrate why prefixing a text producer with sudo cannot redirect into the protected receipt, then save Accepted by team through an appropriately delegated writer. Verify the receipt’s text and root ownership, and establish that the original handoff text remains unchanged.

Before goal 4, predict: does adding learner to the configured team group make every already-running learner shell a team member?

Run it, then compare with your guess

No. Compare the existing process identity with the configured account and with a fresh process. Group membership in the account database does not replace the supplementary groups of the original shell.

  • The initial handoff is a regular file with owner read/write, group read, and other read. Gate is a directory accessible only to its owner.
  • After restriction and group assignment, learner and sam can read the handoff from the inherited practice working directory; nobody is denied.
  • Removing gate’s owner search bit blocks reading its note even though that file’s read bits stay unchanged. Restoring directory search restores access.
  • The transferred handoff is owned by sam and team with rw-r-----. The old learner shell is denied; a fresh learner process can read through its configured supplementary membership.
  • A login-environment identity check reports sam. Su’s learner-targeted command reports learner’s primary group after authenticating that target account.
  • The protected receipt contains the requested line and remains root-owned. The handoff still contains Batch 7 ready.

As in B11.4, relative sam/nobody file reads inherit the existing working directory. They do not demonstrate traversal through learner’s home from outside it.

Hint for identities and modes

With no username, id inspects the running identity. A named lookup reads configured membership. Use a long listing before and after each change. Explicit symbolic classes and the three octal digits should produce the same ordinary bits.

Hint for parent access and ownership

The parent experiment changes directory u-x, not the file’s read bit. A privileged ownership change accepts user:group. A fresh command selected with sudo’s -u obtains that account’s configured group list.

Hint for authentication and the receipt

Su’s -c runs one command and returns. Sudo’s -i requests a login environment. For the receipt, identify which process opens the destination: the invoking shell or a writer that sudo actually launches. Keep the protected receipt separate from the source note.

Solution

Establish the identity and initial metadata.

Terminal window
whoami
Captured output
learner
Terminal window
id
Captured output
uid=1001(learner) gid=1001(learner) groups=1001(learner),27(sudo)
Terminal window
id learner
Captured output
uid=1001(learner) gid=1001(learner) groups=1001(learner),27(sudo),1003(team)

The running shell lacks team. The named lookup includes it. Read the primary gid= separately from the complete groups= list.

Terminal window
ls -l handoff.txt
Captured output
-rw-r--r-- 1 learner learner 14 Nov 14 16:00 handoff.txt
Terminal window
ls -ld gate
Captured output
drwx------ 2 learner learner 4096 Nov 14 16:01 gate

The handoff begins with regular-file marker - and fields rw-, r--, r--. Gate begins with directory marker d and fields rwx, ---, ---.

Restrict the handoff, then assign its sharing group.

Terminal window
chmod u=rw,g=r,o= handoff.txt
Terminal window
ls -l handoff.txt
Captured output
-rw-r----- 1 learner learner 14 Nov 14 16:00 handoff.txt
Terminal window
chmod 640 handoff.txt
Terminal window
ls -l handoff.txt
Captured output
-rw-r----- 1 learner learner 14 Nov 14 16:00 handoff.txt

The two listings have identical mode bits. Assigning a group is a separate operation:

Terminal window
sudo chgrp team handoff.txt
Terminal window
ls -l handoff.txt
Captured output
-rw-r----- 1 learner team 14 Nov 14 16:00 handoff.txt
Terminal window
cat handoff.txt
Captured output
Batch 7 ready
Terminal window
sudo -u sam cat handoff.txt
Captured output
Batch 7 ready
Terminal window
sudo -u nobody cat handoff.txt
Captured output
cat: handoff.txt: Permission denied

Sam matches the group class. Nobody matches the other class, which has no read bit. A successful owner read alone would not prove the sharing policy.

Block and restore a parent lookup.

Terminal window
chmod u-x gate
Terminal window
cat gate/note.txt
Captured output
cat: gate/note.txt: Permission denied
Terminal window
chmod u+x gate
Terminal window
cat gate/note.txt
Captured output
Parent check

No file mode changed between those reads. The missing directory search permission explains the difference.

Transfer the owner and compare old versus fresh identities.

Terminal window
sudo chown sam:team handoff.txt
Terminal window
ls -l handoff.txt
Captured output
-rw-r----- 1 sam team 14 Nov 14 16:00 handoff.txt
Terminal window
cat handoff.txt
Captured output
cat: handoff.txt: Permission denied
Terminal window
sudo -u learner cat handoff.txt
Captured output
Batch 7 ready

The old shell is neither the owner nor a current member of the owning group. The fresh learner process has configured team membership and can use group read permission.

Use selected accounts and bounded login commands.

Terminal window
sudo -u sam -i whoami
Captured output
sam
Terminal window
su - learner -c 'id -gn'

At su’s password prompt, authenticate learner with its own lab password. The command reports learner’s primary group. Sudo’s sam command uses the invoking learner’s delegation, so it does not require a password for sam.

Write the receipt through the process that opens it.

Invalidate the cached authentication, then run a single identity check, answering its prompt with your own password:

Terminal window
sudo -k
sudo whoami
Terminal window
ls -l admin/receipt.txt
Captured output
-rw-r--r-- 1 root root 0 Nov 14 16:01 admin/receipt.txt
Terminal window
sudo printf 'Accepted by team\n' > admin/receipt.txt
Captured output
bash: admin/receipt.txt: Permission denied

Bash tries to open the redirection as learner and fails before sudo starts. Delegate the writer instead:

Terminal window
printf 'Accepted by team\n' | sudo tee admin/receipt.txt
Captured output
Accepted by team
Terminal window
cat admin/receipt.txt
Captured output
Accepted by team
Terminal window
ls -l admin/receipt.txt
Captured output
-rw-r--r-- 1 root root 17 Nov 14 16:01 admin/receipt.txt
Terminal window
sudo -u sam cat handoff.txt
Captured output
Batch 7 ready

The receipt changed while the handoff retained its original text. The receipt’s owner stayed root.

Solution: authenticate and write the protected receipt
learner@rootvolt:~/lab/b11/practice$ sudo -klearner@rootvolt:~/lab/b11/practice$ sudo whoami[sudo] password for learner: rootlearner@rootvolt:~/lab/b11/practice$ sudo printf 'Accepted by team\n' > admin/receipt.txtbash: admin/receipt.txt: Permission deniedlearner@rootvolt:~/lab/b11/practice$ printf 'Accepted by team\n' | sudo tee admin/receipt.txtAccepted by teamlearner@rootvolt:~/lab/b11/practice$ cat admin/receipt.txtAccepted by teamlearner@rootvolt:~/lab/b11/practice$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. The solution authenticates sudo without displaying the password, demonstrates Bash's denied redirection, then writes the receipt through tee.
Steps (17)
  1. Type sudo -k
  2. Press Enter
  3. Type sudo whoami
  4. Press Enter
  5. Output: [sudo] password for learner:
  6. Type the password (the terminal shows nothing)
  7. Press Enter — Type the password (not shown) and press Enter
  8. Output: root
  9. Type sudo printf 'Accepted by team\n' > admin/receipt.txt
  10. Press Enter
  11. Output: bash: admin/receipt.txt: Permission denied
  12. Type printf 'Accepted by team\n' | sudo tee admin/receipt.txt
  13. Press Enter
  14. Output: Accepted by team
  15. Type cat admin/receipt.txt
  16. Press Enter
  17. Output: Accepted by team
Separate source from receipt The handoff is owned by sam and team at mode 640. The separate receipt stays root-owned at mode 644 and is written by delegated tee. Handoff: sam / team, 640 Source text: Batch 7 ready Receipt: root / root, 644 Writer: delegated tee
Separate source from receipt The handoff is owned by sam and team at mode 640. The separate receipt stays root-owned at mode 644 and is written by delegated tee. Handoff: sam / team, 640 Source text: Batch 7 ready Receipt: root / root, 644 Writer: delegated tee
Simplified model. The handoff is owned by sam and team at mode 640; the separate receipt stays root-owned and is written through delegated tee.

In words, sharing the source and writing the administrative receipt are separate permission decisions. The model leaves out the already-accessible working-directory ancestry; it does not grant sam traversal through learner’s home.

Answer before opening each explanation.

1. Why can a numeric UID equal a GID without making them the same identity?

Answer

UIDs identify users; GIDs identify groups. They belong to different identity categories. Their numeric values may coincide, as they do for learner’s primary group in this lab.

2. Does a matching owner also collect more generous group or other permissions?

Answer

No. Basic mode checks select the applicable owner, group, or other class. They do not combine all three fields or fall back to a more generous class.

3. Why can a readable file fail to open through its parent path?

Answer

The path requires search permission on its directory components. A missing parent x can block lookup before the file’s read permission is useful. Directory read permission alone lists names; it does not resolve them.

4. What does 640 grant, and which command changes the owning user instead of those bits?

Answer

Owner read/write, group read, other none. Chown changes owning identities; chmod changes mode bits. Chgrp changes the owning group alone.

5. Why do configured membership and the original shell’s group list disagree after usermod?

Answer

The account database changed, but an existing process keeps its group list. A fresh login or appropriately started substitute process obtains the updated groups. The practice compares both rather than assuming a live shell changed.

6. Why does sudo tee succeed where sudo printf followed by redirection fails?

Answer

Bash opens redirections in the invoking shell before starting the command. In the pipeline, tee opens the specified file while running under sudo’s delegated identity. Su authenticates a target account by a separate path; it does not change that shell redirection rule.

Inspect only the disposable practice directory:

Terminal window
cd ~/lab/b11
ls -AR practice
Terminal window
sudo rm -r ~/lab/b11/practice
sudo userdel -r sam
sudo groupdel team
getent passwd sam
getent group sam
getent group team

The three lookups print no entries and return status 2. Userdel’s absent-mail-spool diagnostic is preserved in the recording; the account, private group, home, and team group are removed. Rerun Before you start to repeat from a clean state.

  • Identify the process, its groups, the resource’s owners, and the applicable access class.
  • File bytes, directory entries, and directory search have separate permission checks.
  • Verify mode and ownership transitions with listings and real account access tests.
  • Select the privileged writer deliberately and preserve the source separately from the receipt.

Next, Packages, repositories, and dependencies explains what a package manager tracks and why its software sources matter.