Based on the Linux Master 1 exam syllabusReport an error
passwd=4755). The biggest privilege-escalation risk point./tmp = 1777.+ at the end of ls -l is the signal of their presence, and the mask is the upper bound.There are problems the 9 bits alone cannot solve. How does a regular user modify /etc/shadow, which only root can write? /tmp is writable by everyone, so why can't you delete other people's files? What if you want to give different permissions to just two people?
chmod, the leading digit is the special permission. The weights are SetUID=4, SetGID=2, Sticky=1.chmod 4755 program # SetUID + rwxr-xr-x
chmod 2755 shareddir # SetGID + rwxr-xr-x
chmod 1777 /tmp # Sticky + rwxrwxrwx
chmod 6755 program # SetUID+SetGID(4+2)| Special Permission | Octal | Where ls Shows It | Effect Summary |
|---|---|---|---|
| SetUID | 4 | owner's x slot → s | Runs with the owner's privileges when executed |
| SetGID | 2 | group's x slot → s | Runs with the owning group's privileges / directory group inheritance |
| Sticky | 1 | other's x slot → t | In a directory, only the owner can delete their own files |
Special permissions appear overlaid on the x slot of the 9-bit permission display. SetUID is shown in the owner's x slot, SetGID in the group's x slot, and Sticky in the other's x slot. If x was originally present it shows as lowercase (s/t), and if x is absent it shows as uppercase (S/T). Uppercase is a warning sign that "the special permission is on but there is no execute permission, so it is effectively meaningless."
An executable file with SetUID set runs with the privileges of that file's owner, no matter who executes it. The representative example is /usr/bin/passwd.
ls -l /usr/bin/passwd
# -rwsr-xr-x 1 root root ... /usr/bin/passwd
# └ s in the owner's x slot = SetUIDThe passwd command must modify /etc/shadow, which only root can write (permissions 000 or 400). How can a regular user alice change her own password? Because passwd has SetUID set and runs with the owner's (root's) privileges, the moment alice runs it, that process can modify shadow with root privileges. Without SetUID, a regular user could not even change their own password. That is the reason SetUID exists.
⚠️ Trap: SetUID is the biggest security threat point. If a program with SetUID has a vulnerability, an attacker can seize root privileges (privilege escalation). In particular, setting SetUID on shell scripts or general-purpose tools like
viandcpis absolutely forbidden (ifcphad root SetUID, anyone could overwrite any file). That is why the Linux kernel ignores SetUID on shell scripts altogether. The command for regularly checking whether the system has unintended SetUID files appears on the exam:
# Search for all SetUID files (the security audit standard)
find / -perm -4000 -type f 2>/dev/null
# Search for SetGID files
find / -perm -2000 -type f 2>/dev/null
# Both SetUID + SetGID
find / -perm /6000 -type f 2>/dev/nullSetGID works in two different contexts.
mkdir /project && chgrp dev /project && chmod 2775 /project
# Now whoever creates a file inside /project, the group is always devA SetGID directory is the key tool for group collaboration. When several people collaborate in one directory, if the group of each person's files differs, they block each other's access. If you set SetGID, all files get a common group, and if you grant group-write (g+w) to that group, the whole team can freely edit each other's files. In Day 3 we said "the group of a new file is the creator's primary group," and the SetGID directory is exactly that exception.
/tmp, this is a disaster — anyone could delete someone else's temporary files. The sticky bit prevents this.ls -ld /tmp
# drwxrwxrwt 10 root root ... /tmp
# └ t in the other's x slot = StickyIn a directory with the sticky bit set, even if you have w permission on the directory, only the file's owner (or the directory's owner, or root) can delete or rename that file. This is why /tmp is 1777 (rwxrwxrwt). Everyone can create files (shared), but cannot delete others' files (protected). Without the sticky bit, anyone could delete others' files in /tmp, causing security and stability problems.
⚠️ Trap: Today the sticky bit has meaning only on directories. In the past (early Unix), it was set on executable files to "keep the program resident in memory/swap" (the origin of the name "sticky"), but modern kernels ignore sticky on files. On the exam, "the sticky bit is used to keep a file resident in memory" is a wrong answer by modern standards.
# Try it yourself — observe and experiment with special permissions
ls -l /usr/bin/passwd /usr/bin/sudo # check SetUID (s)
ls -ld /tmp /var/tmp # check Sticky (t)
mkdir testdir && chmod 2775 testdir && ls -ld testdir # check SetGID (s)
touch testdir/a && ls -l testdir/a # observe group inheritanceIn the 1990s, there was a university server where the sticky bit was missing from /tmp. When one student deleted another student's temporary compile files as a prank, builds failed one after another, and more seriously, a "symlink attack" became possible in which someone deletes a lock file that some program created in /tmp or swaps it for a symbolic link. After the sticky bit was introduced, this attack surface closed. That is why every shared writable directory (/tmp, /var/tmp) must have the sticky bit set.
getfacl file.txt # view the ACL
setfacl -m u:bob:r file.txt # grant read to bob (-m = modify)
setfacl -m g:dev:rw file.txt # read/write for the dev group
setfacl -x u:bob file.txt # remove bob's ACL entry (-x)
setfacl -b file.txt # remove all ACLs (-b = remove all)
setfacl -m d:u:bob:rw dir # default ACL — inherited by children
setfacl -R -m u:bob:rw dir # apply recursivelyThe output structure of getfacl:
# file: file.txt
# owner: alice
# group: dev
user::rw- ← owner (standard owner)
user:bob:r-- ← bob's individual ACL
group::rw- ← owning group (standard group)
group:audit:r-- ← audit group's individual ACL
mask::rw- ← mask (upper bound of ACL permissions)
other::r-- ← other (standard other)For a file with an ACL set, a + sign is attached to the end of the permissions in ls -l (-rw-rwxr--+). Seeing this + is a signal that "this file has an ACL in addition to the standard permissions." On the exam, the answer to "what is the + at the end of the permission display?" is the indicator of an ACL's presence.
The ACL mask is the tricky point. The mask is "the upper bound of the permissions that named users/groups (ACL entries with a name attached) and the owning group can have." Even if you gave bob rwx with setfacl -m u:bob:rwx, if the mask is r--, bob's effective permission stops at r. getfacl attaches an #effective: comment to entries trimmed by the mask to show the actual permissions. Changing the group permissions with chmod actually changes the mask, so you must be careful when applying chmod to a file with an ACL.
Even with an ACL, the standard owner/group/other permissions still exist, and there is an access decision order. ① If the user is the owner, the owner permissions apply → ② if they are in a named user ACL, that entry applies → ③ if they are in the owning group or a named group ACL, one of those applies (limited by the mask) → ④ if none match, other applies. Problems of the "I gave an ACL but the permission doesn't take effect" type are usually cases where the mask is trimming it, or where the user is the owner so the owner permissions apply first.
A company's audit team (the audit group) needed to be able to "only read" a specific log directory. But that directory was already owned by the ops group and the group slot of the standard permissions was occupied by ops. A second group could not be put in with standard permissions, so they added a read + directory-entry ACL for the audit group with setfacl -m g:audit:rX -R /var/log/app. It is a typical case where an ACL solved "different permissions for two groups," which was impossible with the standard permission model. (Uppercase X grants x only to directories/executable files, as seen in Day 3.)
# Try it yourself — ACL experiment
touch acltest.txt
setfacl -m u:nobody:rw acltest.txt
ls -l acltest.txt # confirm the + at the end
getfacl acltest.txt # check the ACL entries and mask
setfacl -b acltest.txt && ls -l acltest.txt # the + disappears after removal| Item | Octal/Command | Key Point |
|---|---|---|
| SetUID | 4xxx, s (owner x) | Runs with the owner's privileges. The passwd example. Security risk |
| SetGID | 2xxx, s (group x) | Group execution / directory group inheritance |
| Sticky | 1xxx, t (other x) | Deletion protection for shared directories. /tmp=1777 |
| SetUID search | find / -perm -4000 | Security audit |
| ACL view/set | getfacl / setfacl -m | Breaking through the owner-group-other limit |
| ACL indicator | + at the end of ls -l | Signal of ACL presence |
/tmp = 1777, passwd = 4755 (rwsr-xr-x), and SetGID directory = group inheritance, you have grasped the essentials.s in the owner's x slot./tmp is 1777.S/T : A warning indicator that the special permission is on but that slot has no execute permission.find / -perm -4000 : The standard security audit command that sweeps the system's SetUID files.getfacl / setfacl : The command that views ACLs and the command that sets/deletes them (-m add, -x delete an entry, -b delete all).+ in ls -l : An indicator that the file has an ACL.setfacl -m d:... that is inherited by newly created children.Click a choice to reveal the answer and explanation.
Question 1
When the permissions of /usr/bin/passwd are displayed as -rwsr-xr-x, what does the s in the owner's x slot mean?
Question 2
Which is correct about the effect of the sticky bit (drwxrwxrwt) set on the /tmp directory?
Question 3
Which is the correct command to find executable files with SetUID set across the whole system?
Question 4
Which is correct about the effect of setting SetGID on a directory (chmod 2775 dir)?
Question 5
What does it mean when a file's permissions as seen with ls -l have a + at the end, like -rw-rwxr--+?
Question 6
Which is the correct ACL command to additionally grant read permission on the file report.txt to user bob only?
Question 7
What is the most appropriate reason the Linux kernel ignores SetUID on shell scripts?