Skip to main content
RunBook Academy

LinuxIII · Filesystems and FilesPermissions

Permissions, ownership, and umask

Foundation⏱ ~12 minbashlschmodchownumask

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

Not yet marked complete on this device.

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
PositionWhat it isExample above
1File kind- (regular file)
2-4Owner permissionsrw- (read + write)
5-7Group permissionsr-- (read only)
8-10Other 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.

Read-only / Safethree permission shapes
$ 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 /tmp

Illustrative output

The numeric mode

Each permission bit has an octal value:

BitValue
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:

ModeMeaning
0644rw-r—r— — public-readable, owner-writable
0755rwxr-xr-x — public-readable and executable, owner-writable
0600rw------- — owner-only read/write
0640rw-r----- — owner read/write, group read-only
0700rwx------ — owner-only full access
0750rwxr-x--- — owner full, group read+execute, no others
Configuration changechmod 0750
$ 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/run

Illustrative output

Symbolic mode

For ad-hoc changes, symbolic mode is often clearer than numeric:

Configuration changesymbolic chmod
$ chmod u+rw,go+r file; chmod g-w file; chmod o=x file; chmod -R u+X .

Illustrative output

Special bits:

BitSymbolicMeaning
setuidu+sProcess runs as file owner
setgidg+sProcess runs as file group; new files inherit directory’s group
sticky+tOn 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.

RequestedumaskResult
0666 (file default)0220644
06660770600
0777 (directory default)0220755
07770020775
Read-only / Safeumask
$ umask
0022

Illustrative output

Ownership with chown and chgrp

Configuration changechown / chgrp
$ chown root:myapp /opt/myapp/config; chgrp myapp /opt/myapp/logs; chown -R myapp:myapp /opt/myapp

Illustrative 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. /tmp has the sticky bit (1777); other shared scratch directories often should too.
  • Scripts lacking execute permission. chmod +x script.sh is the most-frequent fix when a daemon refuses to start.
  • Group ownership of sensitive files. /etc/shadow should be root:shadow mode 0640. Files readable by users or world that contain secrets are a vulnerability.
  • Files with setuid in unexpected places. find / -perm /4000 returns the setuid inventory. Anything outside /usr/bin or /usr/sbin deserves investigation.

Knowledge check

Knowledge check · 3 questions

  1. Q1. A file has mode 0640. The owner can:

  2. Q2. With umask 077, a new file created with mode 0666 will have effective mode 0600.

  3. 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.