Skip to main content
Linux Filesystem Ownership & rwx Permissions
Lesson 2 of 10

Linux Filesystem Ownership & rwx Permissions

Read Linux file ownership and rwx permission strings accurately, distinguish how permissions apply to files versus directories, and apply least-privilege modes safely using chmod and chown.

Beginner 22 min Linux & Windows
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Interpret the file type, permission triplets, owner, and group fields in ls -l output
  • Explain how read, write, and execute bits behave differently on files and directories
  • Modify file permissions using both symbolic and numeric (octal) chmod syntax
  • Identify dangerous permission patterns such as world-writable files and unnecessary SUID binaries

Recommended first: Linux Terminal & FHS Directory Structure

#Why this matters

Navigating Linux directories with ls and find quickly shows you that you cannot read or edit every file on the system. Linux enforces discretionary access control on every file and directory through ownership and permission bits. In both system hardening and beginner Linux challenges, one misconfigured permission -- such as a world-readable SSH key or a world-writable script -- is often the entire difference between a secure host and a compromise.

#Reading ls -l output

Running ls -l prints a ten-character permission field followed by owner and group names:

text
-rw-r----- 1 appadmin auditors 420 Nov 10 09:15 report.conf

Break that first field into four parts:

  1. File type (character 1): - is a regular file, d is a directory, and l is a symbolic link.
  2. Owner (u, characters 2-4): rw- means appadmin can read and write, but not execute.
  3. Group (g, characters 5-7): r-- means members of auditors can read only.
  4. Others (o, characters 8-10): --- means everyone else on the host has no access.

#Files versus directories

The same r, w, and x letters mean different things on a file than on a directory:

Bit On a regular file On a directory
r (4) Read the file's contents List filenames inside the directory (ls)
w (2) Modify or truncate file contents Create, rename, or delete entries inside the directory
x (1) Run the file as a program or script Traverse (cd) into the directory and access file inodes

Pay close attention to directory w: if a user has write permission on a directory, they can delete or replace a file inside it even if they do not own that file, unless the sticky bit protects the directory.

#Symbolic and numeric (octal) modes

You change permissions with chmod and ownership with chown. Note that changing a file's owner with chown normally requires root privileges.

In octal mode, add the weights r = 4, w = 2, and x = 1 for each class:

  • 7 (4+2+1) = rwx, 6 (4+2) = rw-, 5 (4+1) = r-x, 4 = r--, 0 = ---.
  • 600 (rw-------): private keys, tokens, personal secrets.
  • 644 (rw-r--r--): normal non-secret configuration or documentation.
  • 750 (rwxr-x---): scripts or project folders shared with one group.

In symbolic mode, adjust only the bit you want without recalculating the rest: chmod u+x deploy.sh adds execute for the owner, while chmod o-rwx secret.txt strips all access from others.

Inspecting and hardening a lab directory
$ ls -la /tmp/perm-lab
total 8
drwxr-xr-x 2 student student 4096 Nov 12 10:15 .
drwxrwxrwt 9 root    root    4096 Nov 12 10:14 ..
-rwxrwxrwx 1 student student  112 Nov 12 10:15 backup.sh
-rw-r--r-- 1 student student   38 Nov 12 10:15 api_token.txt
$ chmod 600 /tmp/perm-lab/api_token.txt
$ chmod 750 /tmp/perm-lab/backup.sh
$ stat -c "%a %U:%G %n" /tmp/perm-lab/api_token.txt /tmp/perm-lab/backup.sh
600 student:student /tmp/perm-lab/api_token.txt
750 student:student /tmp/perm-lab/backup.sh
  1. Check classOwner (u), Group (g), or Others (o)?
  2. Pick bitsRead (4), Write (2), Execute (1)
  3. Applychmod 600 or chmod o-rwx
  4. Verifyls -l or stat -c "%a %U:%G %n"

#Special bits: SUID, SGID, and sticky bit

Occasionally ls -l shows s or t instead of x:

  • SUID (4xxx, s in owner execute): When executed, the program runs with the file owner's privileges. For example, /usr/bin/passwd is owned by root with -rwsr-xr-x so normal users can update their own password in /etc/shadow. Unnecessary SUID binaries owned by root are a classic privilege-escalation risk.
  • SGID (2xxx, s in group execute): On a directory, new files inherit the directory's group instead of the creator's primary group.
  • Sticky bit (1xxx, t in others execute): Seen on /tmp (drwxrwxrwt). Any user can create files there, but only a file's owner (or root) can delete or rename it.

#Common mistakes

  • Using chmod 777 to fix permission errors: Granting rwx to everyone lets any local account tamper with scripts or read sensitive files. Fix ownership (chown) or group membership instead.
  • Leaving secrets at 644: Default umask values often create files readable by all users (644). Always verify SSH keys, API tokens, and backups with ls -l.
  • Forgetting directory x: Removing x on a folder blocks users from entering or accessing files inside even if they have r.
  • Running chmod -R carelessly: Recursive changes on /etc or /var can break system services and SSH authentication immediately.

#Summary

Linux controls file access using owner, group, and other classes combined with r, w, and x bits, where r, w, and x carry distinct meanings on directories versus regular files. Octal modes like 600 and 750 or symbolic adjustments with chmod let you enforce least privilege, while chown assigns the right owner and group. Recognizing special bits (s and t) and auditing world-readable secrets or world-writable scripts prevents common local exposures.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge