Practice: Users and Basic Permissions
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.
Before you start
Section titled “Before you start”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.
mkdir -p ~/lab/b11/practice/gatecd ~/lab/b11/practicesudo useradd -m -s /bin/bash samsudo groupadd teamsudo usermod -aG team samsudo usermod -aG team learnerprintf 'Batch 7 ready\n' > handoff.txtprintf 'Parent check\n' > gate/note.txtchmod 644 handoff.txt gate/note.txtchmod 700 gatesudo mkdir adminsudo touch admin/receipt.txtsudo chmod 755 adminsudo chmod 644 admin/receipt.txtUse 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.
Your task
Section titled “Your task”Reach these six goals:
- 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.txtandgate. - 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. - 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. - 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. - 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.
- Reauthenticate sudo, demonstrate why prefixing a text producer with sudo cannot redirect into the protected receipt, then save
Accepted by teamthrough 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.
Expected evidence
Section titled “Expected evidence”- 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
Section titled “Solution”Solution
Establish the identity and initial metadata.
whoamilearneriduid=1001(learner) gid=1001(learner) groups=1001(learner),27(sudo)id learneruid=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.
ls -l handoff.txt-rw-r--r-- 1 learner learner 14 Nov 14 16:00 handoff.txtls -ld gatedrwx------ 2 learner learner 4096 Nov 14 16:01 gateThe 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.
chmod u=rw,g=r,o= handoff.txtls -l handoff.txt-rw-r----- 1 learner learner 14 Nov 14 16:00 handoff.txtchmod 640 handoff.txtls -l handoff.txt-rw-r----- 1 learner learner 14 Nov 14 16:00 handoff.txtThe two listings have identical mode bits. Assigning a group is a separate operation:
sudo chgrp team handoff.txtls -l handoff.txt-rw-r----- 1 learner team 14 Nov 14 16:00 handoff.txtcat handoff.txtBatch 7 readysudo -u sam cat handoff.txtBatch 7 readysudo -u nobody cat handoff.txtcat: handoff.txt: Permission deniedSam 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.
chmod u-x gatecat gate/note.txtcat: gate/note.txt: Permission deniedchmod u+x gatecat gate/note.txtParent checkNo file mode changed between those reads. The missing directory search permission explains the difference.
Transfer the owner and compare old versus fresh identities.
sudo chown sam:team handoff.txtls -l handoff.txt-rw-r----- 1 sam team 14 Nov 14 16:00 handoff.txtcat handoff.txtcat: handoff.txt: Permission deniedsudo -u learner cat handoff.txtBatch 7 readyThe 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.
sudo -u sam -i whoamisamsu - 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:
sudo -ksudo whoamils -l admin/receipt.txt-rw-r--r-- 1 root root 0 Nov 14 16:01 admin/receipt.txtsudo printf 'Accepted by team\n' > admin/receipt.txtbash: admin/receipt.txt: Permission deniedBash tries to open the redirection as learner and fails before sudo starts. Delegate the writer instead:
printf 'Accepted by team\n' | sudo tee admin/receipt.txtAccepted by teamcat admin/receipt.txtAccepted by teamls -l admin/receipt.txt-rw-r--r-- 1 root root 17 Nov 14 16:01 admin/receipt.txtsudo -u sam cat handoff.txtBatch 7 readyThe receipt changed while the handoff retained its original text. The receipt’s owner stayed root.
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$ Steps (17)
- Type
sudo -k - Press Enter
- Type
sudo whoami - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter — Type the password (not shown) and press Enter
- Output:
root - Type
sudo printf 'Accepted by team\n' > admin/receipt.txt - Press Enter
- Output:
bash: admin/receipt.txt: Permission denied - Type
printf 'Accepted by team\n' | sudo tee admin/receipt.txt - Press Enter
- Output:
Accepted by team - Type
cat admin/receipt.txt - Press Enter
- Output:
Accepted by team
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.
Recall check
Section titled “Recall check”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.
Reset this lesson
Section titled “Reset this lesson”Inspect only the disposable practice directory:
cd ~/lab/b11ls -AR practicesudo rm -r ~/lab/b11/practicesudo userdel -r samsudo groupdel teamgetent passwd samgetent group samgetent group teamThe 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.
Further reading
Section titled “Further reading”- On your system:
man id,man chmod,man chown,man chgrp,man sudo,man su, andman path_resolution. - GNU Coreutils: File permissions.
- Linux man-pages: Path resolution.
- Ubuntu: User management.