Pcornel
Linux

Permissions & Ownership

Cheat sheet · https://pcornel.dk/topic.php?topic=2705

Back to the Topic

Answer

Every file has an owner, a group and permission bits for owner, group and others: read (r), write (w) and execute (x). For directories, x means "may enter", r "may list" and w "may create and delete names".

Remember

The kernel checks owner first, then group, then others — only the first matching class counts. Every directory on the path needs x. root bypasses most checks; services run as their own user. Beyond mode bits, ACLs, SELinux/AppArmor and mount options (ro, noexec) can still deny access.

First checks

  • ls -l <path> — owner, group and mode
  • stat -c '%A %a %U:%G' <path> — symbolic and numeric mode with owner
  • namei -l <path> — permissions of every directory on the path
  • id <user> — user's groups

Commands

chmod
Change discretionary permission mode bits on files or directories.
chown
Change file or directory ownership and optionally the owning group.
chgrp
Change the owning group of filesystem objects.
umask
Display or set the shell mask that removes default permission bits from newly created objects.

Verify in this order

user identified → owner / group / other class chosen → x on every parent directory → r/w/x bit for the operation → ACL and MAC checks → access

Where it usually breaks

First mismatch in identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2705

Confirmation

Confirm action

Continue?