How to Use chmod to Change File Permissions in Linux

This article provides a comprehensive guide on using the chmod (change mode) command to manage file and directory permissions in the Linux operating system. You will learn the fundamentals of the Linux permission model, how to read access rights, and the step-by-step application of both numeric (octal) and symbolic notations to secure or grant access to files.


Understanding Linux File Permissions

Every file and directory in Linux has an assigned set of permissions categorized by three user types:

Each category can have three standard types of access:

When running ls -l, permissions appear as a 10-character string (e.g., -rwxr-xr--). The first character indicates the file type (- for file, d for directory), followed by three triplets representing permissions for User, Group, and Others.


Method 1: Using Numeric (Octal) Mode

Numeric mode represents permissions using three-digit numbers. Each permission type has an assigned numeric value:

Add the values together to generate a single digit for each user category:

Syntax:

chmod [numeric_code] [filename]

Common Examples:


Method 2: Using Symbolic Mode

Symbolic mode uses characters and mathematical operators to modify specific permissions without needing to calculate numeric values.

Operators:

Syntax:

chmod [who][operator][permission] [filename]

Common Examples:


Applying Permissions Recursively

To apply permission changes to a directory and all files and subdirectories within it, use the -R (recursive) flag:

chmod -R 755 /path/to/directory

Note: Be cautious when running recursive chmod commands, especially with root privileges, as incorrectly altering system file permissions can cause system instability.