Website Vidya
SecurityStep-by-Step Guide

Linux File Permissions Explained: Octal & Symbolic Guide

Learn linux file permissions with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

RR
Rajesh RayLead Systems Educator
Published:
11 min read
PDF Cheat Sheet
Linux File Permissions Explained: Octal & Symbolic Guide
AI Executive SummaryWebsiteVidya AI

11 min read

Learn linux file permissions with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

Key Highlights
  • What chmod Does and When to Use It
  • Availability and Installation Across Linux Distributions
  • Command Syntax, Arguments, and Exit Status Codes
Grounded in full engineering runbookWebsiteVidya AI Engine

A deep understanding of linux file permissions is the foundation of multi-user operating system security, server hardening, and application isolation. Every file, directory, named pipe, socket, and device node created on a Linux filesystem contains discretionary access control (DAC) metadata stored within its inode table entry.

When a process attempts to read, modify, or execute an object, the Linux kernel evaluates the process's effective user ID (EUID) and effective group IDs (EGID) against the target inode's mode bits. Access is checked in a strict precedence order: if the process matches the file owner, user permission bits apply; if not, but the process belongs to the file's group, group bits apply; otherwise, other (world) permission bits govern access.

This technical guide explains how read, write, and execute bits function across both regular files and directories, breaks down octal numeric versus symbolic representations, demonstrates how the process umask calculates default permissions, and walks through auditing tools like stat and ls -l.

Advertisement
Linux File Permissions Explained: Octal & Symbolic Guide — syntax, flags, and practical terminal workflow diagram
Linux File Permissions Explained: Octal & Symbolic Guide — command syntax, key options, and production workflow reference.

What chmod Does and When to Use It

In the Linux Virtual File System (VFS), an inode stores permissions inside a 16-bit integer field named st_mode. The highest 4 bits define the file type (regular file, directory, symbolic link, character device, block device, FIFO pipe, or UNIX domain socket). The remaining 12 bits encode access permissions: 3 special attribute bits (SUID 04000, SGID 02000, and Sticky Bit 01000), followed by 9 standard permission bits divided into three sets of 3 bits each for User (owner), Group, and Other.

The interpretation of permission bits differs significantly between regular files and directories. For a regular file, Read (r) permits viewing data bytes, Write (w) permits altering or truncating bytes, and Execute (x) allows the kernel's execve(2) system call to load the file into memory as a binary program or interpreter script. For a directory, Read (r) allows listing directory entries (filenames) via readdir(3), Write (w) allows creating, renaming, or unlinking entries within the directory (provided execute is also present), and Execute (x), also called the search bit, allows traversing into the directory and accessing inodes referenced by its entries.

Linux enforces discretionary access control (DAC) by evaluating the effective User ID (EUID), effective Group ID (EGID), and supplementary groups against inode permission bits. When chmod executes, the Virtual File System (VFS) and active Linux Security Modules (SELinux or AppArmor) validate the caller's privileges before committing changes to disk or account databases.

Availability and Installation Across Linux Distributions

The chmod utility is packaged in coreutils across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:

Advertisement

Before running administrative tasks or automation scripts, verify whether chmod is installed and inspect which binary path and version your shell resolves:

type -a chmod
chmod --version 2>/dev/null || man -f chmod

# Illustrative output (reviewed against documentation)
chmod is /usr/bin/chmod
chmod (coreutils)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y coreutils

# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y coreutils

# Arch Linux
sudo pacman -S --noconfirm coreutils

# Alpine Linux
sudo apk add --no-cache coreutils

Command Syntax, Arguments, and Exit Status Codes

chmod [OPTION]... MODE[,MODE]... FILE... | stat -c "%a %A %n" FILE...

File permissions are primarily inspected using ls -l or stat [OPTION]... FILE... and modified using chmod [OPTION]... MODE FILE.... The 10-character string rendered by ls -l (e.g., -rwxr-xr--) begins with a file type indicator (- for regular file, d for directory, l for symlink), followed by three triplets representing User (rwx), Group (r-x), and Other (r--).

Octal notation assigns a weighted numeric value to each permission bit: Read = 4, Write = 2, and Execute = 1. Summing the weights yields a single octal digit (0 through 7) for each class: 7 (4+2+1 = rwx), 6 (4+2 = rw-), 5 (4+1 = r-x), and 4 (4 = r--). A mode of 755 signifies User=rwx (7), Group=r-x (5), and Other=r-x (5).

  • 0 — Successful permission query or modification.
  • 1 — Minor operational failure, such as attempting to modify a file without sufficient ownership or permissions.
  • 2 — Syntax error or invalid mode argument provided to chmod or stat.

Important Options and Flags Reference

Option / FlagLong Form / ArgumentTechnical Behavior and Purpose
-c--changesLike verbose, but reports only when a change is actually made to a file mode.
-v--verboseOutputs a diagnostic message for every file processed by chmod.
-R--recursiveRecursively applies mode changes across files and subdirectories.
--reference--reference=RFILECopies the permission mode of reference file RFILE instead of specifying an explicit mode.
u, g, o, aUser, Group, Other, AllSymbolic classes: user (owner), group, others, and all (user + group + others).
+, -, =Add, Remove, AssignSymbolic operators: add permission, remove permission, and assign exact permission.
r, w, xRead, Write, ExecuteStandard permission bits: read (4), write (2), and execute (1).
XConditional ExecuteConditional execute: grants execute only if the target is a directory or already has execute set for some user.

When managing permissions, deciding between numeric octal mode (e.g., chmod 644 file.txt) and symbolic notation (e.g., chmod u+x file.sh) depends on operational context. Octal mode sets an absolute permission state, completely overwriting existing bits regardless of prior configuration. This is ideal for provisioning and infrastructure as code.

Advertisement

In contrast, symbolic modifiers (like chmod g+w,o-rwx file.txt) perform incremental bitwise mutations without altering unrelated bits. Symbolic notation is safer during interactive administrative tasks where you need to add execute rights to an executable script (chmod +x script.sh) without having to calculate or disturb the existing read and write permissions of the file.

When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.

Practical Basic and Advanced Usage Examples

1. Inspect File Permissions in Long Listing Format

Use ls -l to display file type, symbolic permissions, link count, owner, group, file size, and timestamp.

touch test_file.txt && chmod 640 test_file.txt
ls -l test_file.txt

# Illustrative output (reviewed against documentation)
-rw-r----- 1 admin webapps 0 Oct 22 20:25 test_file.txt

The first character '-' indicates a regular file. 'rw-' grants read/write to user admin, 'r--' grants read-only to group webapps, and '---' denies all access to others.

2. Display Octal and Human-Readable Permissions with stat

Use the stat command to extract exact numeric octal permissions alongside symbolic representation.

stat -c "File: %n | Octal: %a | Symbolic: %A | Owner: %U:%G" test_file.txt

# Illustrative output (reviewed against documentation)
File: test_file.txt | Octal: 640 | Symbolic: -rw-r----- | Owner: admin:webapps

The format flags %a and %A extract the exact 3-digit octal and 10-character symbolic modes cleanly for scripts.

3. Set Standard Permissions for a Regular File (644)

Apply the standard security baseline for configuration and document files: read/write for owner, read-only for all others.

chmod 644 config.json
ls -l config.json

# Illustrative output (reviewed against documentation)
-rw-r--r-- 1 admin admin 512 Oct 22 20:26 config.json

Mode 644 represents User=4+2 (rw), Group=4 (r), and Other=4 (r), preventing unauthorized users from modifying configuration files.

4. Set Standard Permissions for an Executable Script (755)

Grant execute privileges to a shell script while protecting it from modification by non-owners.

chmod 755 deploy.sh
ls -l deploy.sh

# Illustrative output (reviewed against documentation)
-rwxr-xr-x 1 admin admin 1024 Oct 22 20:27 deploy.sh

Mode 755 assigns read, write, and execute (7) to the owner, and read and execute (5) to group members and other users.

5. Modify Permissions Incrementally Using Symbolic Notation

Add group write permissions while stripping all permissions from others without altering owner bits.

chmod g+w,o-rwx shared_doc.txt
ls -l shared_doc.txt

# Illustrative output (reviewed against documentation)
-rw-rw---- 1 admin team 2048 Oct 22 20:28 shared_doc.txt

Symbolic operators add write to group (g+w) and remove read, write, and execute from other (o-rwx) cleanly.

6. Inspect Default umask Calculation for Newly Created Files

View the active umask value and demonstrate how the kernel computes default permissions for new files and directories.

umask
# Demonstrating creation:
touch new_file.txt && mkdir new_dir
stat -c "%a %A %n" new_file.txt new_dir

# Illustrative output (reviewed against documentation)
0022
644 -rw-r--r-- new_file.txt
755 drwxr-xr-x new_dir

The umask 0022 subtracts write from group and others, converting base file mode 666 to 644, and base directory mode 777 to 755.

Real-World Workflows, Pipelines, and Shell Automation

System-Wide Permission Hardening Audit for Sensitive Files

Audit sensitive system configuration files (/etc/shadow, /etc/passwd, SSH keys) to ensure permissions comply with CIS security benchmarks and do not expose credentials.

# Audit critical configuration files for overly permissive bits
FILES=("/etc/passwd" "/etc/shadow" "/etc/ssh/sshd_config")
echo "Auditing security permissions..."
for f in "${FILES[@]}"; do
  if [ -e "$f" ]; then
    stat -c "Permission: %a | Mode: %A | Owner: %U:%G | File: %n" "$f"
  fi
done

# Illustrative output (reviewed against documentation)
Auditing security permissions...
Permission: 644 | Mode: -rw-r--r-- | Owner: root:root | File: /etc/passwd
Permission: 640 | Mode: -rw-r----- | Owner: root:shadow | File: /etc/shadow
Permission: 600 | Mode: -rw------- | Owner: root:root | File: /etc/ssh/sshd_config

Confirms that /etc/shadow is restricted to root:shadow and sshd_config is readable only by root (600), preventing unauthorized credential leaks.

Shared Collaborative Group Directory Provisioning

Configure a shared collaborative folder where team members can create and modify files while inheriting group ownership automatically.

sudo mkdir -p /srv/teamdata
sudo chown -R root:developers /srv/teamdata
# Grant read/write/execute and set SGID (2775)
sudo chmod 2775 /srv/teamdata
# Verify SGID bit
ls -ld /srv/teamdata

# Illustrative output (reviewed against documentation)
drwxrwsr-x 2 root developers 4096 Oct 22 20:30 /srv/teamdata

The 's' in the group execute position represents the Set Group ID (SGID) bit (2775), ensuring that any new files created inside inherit group 'developers'.

Pipelines, Redirection, Quoting, and Shell Expansion

When embedding chmod inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.

Permissions, Security Implications, and Safe Execution

In Linux DAC security, permission checks terminate on the first match. If you own a file with permissions 000 (no permissions) and belong to a group with 777 permissions, you will be denied access because your identity matches the owner class first, where all access is explicitly disabled.

Beyond standard DAC bits, modern Linux systems deploy POSIX Access Control Lists (ACLs, via getfacl/setfacl) for fine-grained multi-user authorization, as well as Mandatory Access Control (MAC) systems like SELinux and AppArmor that enforce security policies regardless of file permission bits.

GNU/Linux, BSD, and BusyBox Implementation Differences

Standard DAC permissions (rwx for User, Group, Other) and umask handling are standardized under POSIX.1-2017 and operate identically across Linux, FreeBSD, OpenBSD, and macOS.

However, extended permissions, default ACL inheritance, and security context attributes (like SELinux contexts displayed by ls -Z) are Linux-specific. Filesystems like FAT32 and exFAT do not support POSIX permission bits natively; when mounted in Linux, permissions are simulated globally via mount options (umask, dmask, fmask).

Troubleshooting Common Errors and Diagnostics

Cannot access file despite having read permissions (-rw-r--r--)

Root Cause: The user lacks execute (x) search permissions on one or more parent directories along the path leading to the target file.

Resolution: Check the permissions of every ancestor directory leading to the file. Ensure that each directory has at least execute (x) permissions for the user or group.

namei -l /var/www/html/app/config.json

Script fails with 'bash: ./script.sh: Permission denied'

Root Cause: The script file lacks execute (x) mode bits, or the filesystem is mounted with the 'noexec' mount option.

Resolution: Add execute permission to the file using chmod +x script.sh, or verify mount options using findmnt if execute is already enabled.

chmod +x script.sh
./script.sh

chmod: changing permissions of 'file': Operation not permitted

Root Cause: Only the owner of a file or the root superuser has the authority to modify its permission mode bits.

Resolution: Check file ownership using ls -l. If you are not the file owner, run the command with sudo or ask the file owner to execute the change.

ls -l file.txt
sudo chmod 644 file.txt

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
In Linux octal notation, each digit represents permissions for User, Group, and Others. 755 translates to rwxr-xr-x (owner has full rights; group and others can read and execute). 644 translates to rw-r--r-- (owner can read and write; group and others can only read). 644 is standard for files, and 755 is standard for directories and scripts.
On a directory, the execute permission (also called the search bit) allows a user to enter (cd into) the directory and access metadata/inodes of files inside. Without execute permission, you cannot open files or traverse into subdirectories, even if you have read permission on the directory.
The Linux kernel assigns default permissions of 666 to regular files and 777 to directories. The system umask (typically 0022) is subtracted bitwise from these defaults, resulting in 644 (666 - 022) for new files and 755 (777 - 022) for new directories.
These are special permission bits. SUID (4000) causes an executable to run with the permissions of the file owner (e.g. passwd). SGID (2000) makes files inherit the group of the parent directory. The Sticky Bit (1000) on directories (like /tmp) prevents users from deleting files owned by others.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout