Based on the Linux Master 1 exam syllabusReport an error
usermod -G alone wipes the existing secondary groups — always use -aG./tmp Sticky.This week covered the skeleton of Linux security. We connect the four pieces (account files → management commands → permission arithmetic → special permissions and ACLs) into a single picture.
| File | Permissions | Field Count | Key Fields | Partner |
|---|---|---|---|---|
| /etc/passwd | 644 | 7 | UID(3) · GID(4) · home(6) · shell(7) | shadow |
| /etc/shadow | 400/640 | 9 | hash(2) · LastChange(3) · Min(4) · Max(5) | passwd |
| /etc/group | 644 | 4 | GID(3) · secondary members(4) | gshadow |
| /etc/gshadow | 400 | 4 | group password(2) · administrators(3) | group |
Points to lock into memory:
passwd↔shadow and group↔gshadow are pairs split into "public (644, identity/membership) and secret (400, hashes/policy)." Consistency is checked with pwck (passwd/shadow) and grpck (group/gshadow).
| Command | Key Options | Trap to Watch |
|---|---|---|
| useradd | -u -g -G -d -s -m -c | -g (primary, one) vs -G (secondary, several) |
| usermod | -aG (add) / -G (replace) | Forgetting -a loses existing secondary groups |
| userdel | -r (delete home too) | Without the option the home remains |
| passwd | -l (lock) -u -e (expire) -d (delete) | -l (block) and -d (no password) are opposites |
| chage | -M (Max) -m (Min) -W -E | Uppercase M=Max, lowercase m=Min |
| gpasswd | -a -d -A | Updates group+gshadow at the same time |
⚠️ Trap Review:
usermod -G(alone) wipes the existing secondary groups and replaces them. Always-aG. You can assume this shows up on the exam every week.
| Category | su | sudo |
|---|---|---|
| Password required | Target user's password | Your own password |
| Scope | Continue as that person after switching | Delegates a single command only |
| Config file | None | /etc/sudoers (edit with visudo) |
| Audit | Difficult (shared password) | Left in the log (/var/log/secure) |
| Login shell | su - (fully applies environment) | sudo -i |
The hyphen in su - = login shell (fully applies the target's environment). sudoers specifies groups with % (Red Hat=wheel, Ubuntu=sudo). Always edit with visudo (syntax check + lock).
| Conversion | Rule |
|---|---|
| Weights | r=4, w=2, x=1 |
| Order | owner→group→other, each r→w→x |
| 644 | rw-r--r-- (regular file) |
| 755 | rwxr-xr-x (executable/directory) |
| 600 | rw------- (secret file) |
| umask file | 666 − umask |
| umask directory | 777 − umask |
⚠️ Trap Review: umask 022 → file 644, directory 755. Files start from 666 and directories from 777 (files exclude x by default). The larger the umask, the more restrictive.
On a directory, x = entry (cd), and deleting a file depends not on the file but on the directory's w permission. chown (changing the owner) is possible only for root.
| Item | Octal | Display | Effect |
|---|---|---|---|
| SetUID | 4 | owner x→s | Runs with the owner's privileges (passwd=4755) |
| SetGID | 2 | group x→s | Group execution/directory group inheritance |
| Sticky | 1 | other x→t | Deletion protection for shared directories (/tmp=1777) |
| ACL | setfacl -m | + in ls | Individual user/group permissions |
The kernel ignores SetUID on shell scripts (for security). SetUID search = find / -perm -4000. If an ACL exists, there is a + at the end of the ls -l permissions. The mask is the upper bound of named user/group permissions.
Scenario A — Building a new collaboration directory
groupadd devteam
usermod -aG devteam alice
usermod -aG devteam bob
mkdir /shared && chgrp devteam /shared
chmod 2775 /shared # SetGID: all new files inherit the devteam groupScenario B — New employee account + forced change at first login
useradd -m -s /bin/bash -c "New Hire" newbie
passwd newbie # set the initial password
chage -d 0 newbie # force a password change at next login
chage -M 90 -W 7 newbie # change every 90 days, warn 7 days beforeScenario C — Security check
awk -F: '$3==0{print $1}' /etc/passwd # UID 0 accounts (only root is normal)
find / -perm -4000 -type f 2>/dev/null # suspicious SetUID
ls -ld /tmp # check StickyThe first step of real-world breach incident analysis is exactly these three — a UID 0 backdoor account, abnormal SetUID binaries, and a missing Sticky on /tmp. Since a one-line command can instantly check the key holes in system security, this week's content is the basis of real-world security beyond the exam.
pwck / grpck : Commands that check the consistency of the two pairs.-g vs -G : The option that sets one primary group, and the option that sets several secondary groups.usermod -aG : Adds while keeping existing secondary groups. Forgetting -a replaces them wholesale.chage -d 0 : A technique that sets the last change date to 0 to force a password change at the next login.su - : An indicator to fully apply the target user's login environment (PATH·HOME·profile).visudo : The dedicated command that edits sudoers with syntax checking and locking.Click a choice to reveal the answer and explanation.
Question 1
Among the 9 fields of /etc/shadow, which field indicates "the minimum number of days after the password was last changed until it can be changed again"?
Question 2
Which correctly expresses a file with permissions rwxr-x--- in octal and correctly explains its meaning?
Question 3
You want to add user alice to the wheel group while keeping her existing secondary groups. Which is the correct command?
Question 4
When umask is 027, what are the permissions of a newly created directory?
Question 5
Which is correct about su and sudo?
Question 6
What is the most appropriate reason the /tmp directory has permissions 1777 (drwxrwxrwt)?
Question 7
What is the most accurate reason the executable file /usr/bin/passwd needs SetUID?
Question 8
For the file data.csv, the ls -l result is shown as -rw-rw-r--+. Which is correct about what the trailing + sign means and the command to confirm it?
Question 9
During a security check, running awk -F: '$3==0 {print $1}' /etc/passwd printed two names, root and backdoor. What does this result mean?
Question 10
You applied chmod 2770 /share to the directory /share and set the group to team. Which is the most accurate effect of this setting?
Question 11
You want to create a new user account while creating the home directory and copying the default configuration files from /etc/skel. Which is the correct command?
Question 12
Which is correct about the difference between passwd -l user1 and passwd -d user1?