skip to content

On Linux, a file is owned by user alice and group devs with mode 0466 (r--rw-rw-), and alice is a member of devs. Can alice write to that file, and why?

level: middleimportance: nice to knowfreq 30%

answer

  1. three classes, one match
  2. the check stops at the first hit
  3. owner bits win even when stingier
  4. group membership cannot rescue the owner
  5. ownership still allows chmod

basics

~20 s

No. The kernel picks exactly one permission class and stops: because alice's effective UID owns the file, only the owner triad applies, and that is read-only. The group and other bits are never consulted for her.

solid answer

~50 s

No, alice cannot write it. Permission checking selects a **single** class and does not fall through to the others. If the process's effective UID matches the file's owner, the owner triad decides the outcome — full stop. Otherwise, if the effective GID or one of the supplementary groups matches the file's group, the group triad decides. Only when neither matches do the other bits apply. So alice is judged solely by `r--`, even though she is in `devs` and the group triad grants write, and even though `others` grants write to literally everyone else on the machine. This surprises people because they picture the three triads as accumulating. They do not — the classes are mutually exclusive, and being the owner can leave you with *less* access than a stranger. Alice is not stuck, though: ownership carries the right to change the mode, so `chmod u+w` fixes it immediately.

code

bash · 8 lines
bash
touch /tmp/odd
chmod 0466 /tmp/odd
ls -l /tmp/odd
# As the owner, this fails even though group and other have write:
echo hi > /tmp/odd
# But the owner may always change the mode:
chmod u+w /tmp/odd
echo hi > /tmp/odd

go deeper

for a junior

Remember that only one of the three triads applies to you — the first one that matches — and that owning a file does not automatically mean you can write it.

for a middle

State the selection order precisely: owner UID match, then group or supplementary group match, then other, with exactly one branch running and no fallback. Explain why a union model would make restrictions inexpressible.

for a senior

Use it diagnostically: when an account fails despite correct group membership, check whether it owns the file, and remember that reproducing as root proves nothing because privileged processes bypass the check.

for a principal

Recognise this as an argument about expressiveness — nine bits give you three exact statements and no more — and decide when a workload's sharing requirements have outgrown them and warrant a different access-control mechanism.

## The check is a selection, not an accumulation Most people carry a mental model in which permission grows as you match more categories: you are in the group, so you get the group's rights *added* to yours. That model is wrong, and this scenario is the standard way interviewers expose it. The kernel's discretionary access check works like this, in order: 1. If the process's effective UID equals the file's owner UID → **use the owner triad and stop**. 2. Else, if the effective GID or any supplementary group of the process equals the file's group GID → **use the group triad and stop**. 3. Else → **use the other triad**. Exactly one branch runs. There is no union, no maximum, no fallback to a more generous class if the selected one denies the operation. Applied to the example — owner `alice`, group `devs`, mode `r--rw-rw-`: | Who | Class selected | Effective rights | |---|---|---| | alice | owner | read only | | bob, member of devs | group | read and write | | carol, unrelated | other | read and write | The owner has strictly less access than anyone else on the system. That is not a bug; it is the specified behaviour, and it is occasionally used deliberately as a self-protection measure against accidental overwrites. ## Why it is designed this way A union model would make it impossible to express "this class specifically may not do X". If matching more categories always meant more rights, you could never restrict the owner while permitting the group, and a mode's meaning would depend on group membership you cannot see from the mode. The select-one rule keeps each triad an exact statement about that class, which is also what makes a mode readable at a glance. ## The escapes Two things sit outside this rule. **Ownership is not the same as access.** Alice cannot write the contents, but she *can* change the mode, because the right to `chmod` a file belongs to its owner regardless of the permission bits. The restriction is therefore advisory against accident rather than a security boundary against the owner: ``` $ echo hi > /tmp/odd bash: /tmp/odd: Permission denied $ chmod u+w /tmp/odd # allowed: alice owns it $ echo hi > /tmp/odd # now fine ``` **Privileged processes bypass the check entirely.** Root — more precisely, a process holding the capability that overrides discretionary access checks — is not subject to the triad selection at all, which is why testing a permissions theory as root proves nothing. Always reproduce the failure as the account that actually hit it. ## How it shows up in the real world It is rarely mode `0466` in production; the realistic shapes are: - **A service account that owns a directory whose owner bits are tighter than the group bits.** A deployment step wrote `chmod 0470` intending to give the group access, and the service — which owns the directory — quietly lost write access. Adding it to another group changes nothing, because the owner branch is what runs. - **A shared area where an account was added to the right group but is also the file owner.** Group membership is the fix people try first, and it has no effect for files that account already owns. The diagnostic instinct to build: when a permission failure looks impossible given the group membership, check whether the failing account is the **owner**. If it is, group membership is irrelevant to the outcome and you must look at the owner triad. A further practical note: group membership is established when the process's credentials are set, typically at login. Adding a user to a group does not change the supplementary groups of processes that are already running, so an already-open session may still be judged by the other class even after the membership change lands. That is a separate trap from the one in this question, but it appears in the same conversations. ## The one-sentence answer No — the kernel selects one class, ownership wins that selection, and the owner triad here grants read only; alice's `devs` membership is never consulted, though she may `chmod` the file because she owns it.

  • Is there any way for alice to write that file without changing its mode?
    Not through the ordinary check, because ownership selects the owner triad and it denies write. A privileged process can bypass discretionary checks entirely, and a per-file access-control entry naming her is a separate mechanism that can override the picture — but within the nine mode bits alone, no group membership or class stacking will help her.
  • A user was just added to a group but still gets permission denied. What is going on?
    Two possibilities. Either the failing account owns the file, in which case the owner triad decides and group membership is irrelevant. Or the group change has not reached the running process — supplementary groups are fixed in a process's credentials when they are established, so an existing session keeps its old set until the user starts a new one.
  • Why would anyone deliberately give the owner fewer permissions than the group?
    As a guard against accident rather than against attack. Clearing the owner's write bit on a file that must not be casually overwritten forces a deliberate `chmod` before any change, which turns an accidental redirect or editor save into an error. It is not a security control, since the owner can lift it at will.

It works like a badge check with a single desk: the guard reads the first line of your badge that matches and applies exactly that rule, rather than adding up every list your name appears on.

saying these in an interview costs you the question

  • Believing the three triads accumulate into a union of rights
  • Assuming the owner always has at least the group's permissions
  • Thinking group membership can grant access to a file you own
  • Testing the theory as root and concluding permissions are fine
  • Confusing the right to chmod a file with the right to write its contents

context