LinuxIII · Filesystems and FilesPermissions
Permissions, ownership, and umask
What you'll learn
- Read every character of `ls -l` output
- Calculate effective permissions from mode and umask
- Use chmod in both numeric and symbolic notation
- Choose appropriate permission sets for production files
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09
Every file on Linux has an owner, a group, and three sets of permission bits. Reading them correctly is the difference between “why is this script failing” and “ah, it’s missing the execute bit”.
The permission string
ls -l shows ten characters:
-rw-r----- 1 root adm 4321 Aug 9 11:11 /var/log/syslog
| Position | What it is | Example above |
|---|---|---|
| 1 | File kind | - (regular file) |
| 2-4 | Owner permissions | rw- (read + write) |
| 5-7 | Group permissions | r-- (read only) |
| 8-10 | Other permissions | --- (none) |
The three permission sets are evaluated in order: owner first; if the requesting user is not the owner, then group; if not a member of the group, then other.
$ ls -l /usr/bin/systemctl /etc/shadow /tmp-rwxr-xr-x 1 root root 320K Aug 9 11:11 /usr/bin/systemctl
-rw-r----- 1 root shadow 1.8K Aug 9 11:11 /etc/shadow
drwxrwxrwt 1 root root 128 Aug 9 11:11 /tmpIllustrative output
The numeric mode
Each permission bit has an octal value:
| Bit | Value |
|---|---|
Read (r) | 4 |
Write (w) | 2 |
Execute (x) | 1 |
Sum the values for each set. chmod 0640 file is read-write for
owner, read-only for group, nothing for other.
Common modes:
| Mode | Meaning |
|---|---|
| 0644 | rw-r—r— — public-readable, owner-writable |
| 0755 | rwxr-xr-x — public-readable and executable, owner-writable |
| 0600 | rw------- — owner-only read/write |
| 0640 | rw-r----- — owner read/write, group read-only |
| 0700 | rwx------ — owner-only full access |
| 0750 | rwxr-x--- — owner full, group read+execute, no others |
$ chmod 0750 /opt/myapp/bin/run; ls -l /opt/myapp/bin/run-rwxr-x--- 1 root myapp 8.2K Aug 9 11:11 /opt/myapp/bin/runIllustrative output
Symbolic mode
For ad-hoc changes, symbolic mode is often clearer than numeric:
$ chmod u+rw,go+r file; chmod g-w file; chmod o=x file; chmod -R u+X .Illustrative output
Special bits:
| Bit | Symbolic | Meaning |
|---|---|---|
| setuid | u+s | Process runs as file owner |
| setgid | g+s | Process runs as file group; new files inherit directory’s group |
| sticky | +t | On a directory, only the file’s owner can delete or rename files inside |
umask — the default-permission mask
When a process creates a new file, the kernel applies the umask to the requested mode to derive the effective mode.
| Requested | umask | Result |
|---|---|---|
| 0666 (file default) | 022 | 0644 |
| 0666 | 077 | 0600 |
| 0777 (directory default) | 022 | 0755 |
| 0777 | 002 | 0775 |
$ umask0022Illustrative output
Ownership with chown and chgrp
$ chown root:myapp /opt/myapp/config; chgrp myapp /opt/myapp/logs; chown -R myapp:myapp /opt/myappIllustrative output
Common production permission mistakes
- World-writable files.
find / -perm -o+w -type f -not -path '/proc/*' -not -path '/sys/*'should return very little. Anything it returns deserves investigation. - World-writable directories without sticky bit.
/tmphas the sticky bit (1777); other shared scratch directories often should too. - Scripts lacking execute permission.
chmod +x script.shis the most-frequent fix when a daemon refuses to start. - Group ownership of sensitive files. /etc/shadow should be
root:shadowmode 0640. Files readable byusersorworldthat contain secrets are a vulnerability. - Files with setuid in unexpected places.
find / -perm /4000returns the setuid inventory. Anything outside/usr/binor/usr/sbindeserves investigation.
Knowledge check
Knowledge check · 3 questions
Q1. A file has mode 0640. The owner can:
Q2. With umask 077, a new file created with mode 0666 will have effective mode 0600.
Q3. Which of the following are appropriate permission sets for production files? Select all that apply.
Passing score: 75%. Answers are checked in this browser.