Fundamentals 10 min read

Mastering Linux chmod: A Complete Guide to File Permission Management

This tutorial explains Linux file permissions, the chmod command syntax, numeric and symbolic modes, recursive options, and practical examples, enabling readers to confidently view, modify, and troubleshoot permissions for files and directories.

ITPUB
ITPUB
ITPUB
Mastering Linux chmod: A Complete Guide to File Permission Management

The Linux chmod command changes or assigns permissions for files and directories. Permissions are determined by ownership (user, group, others) and three basic rights: read ( r), write ( w), and execute ( x). Permissions can be expressed in symbolic form or octal numbers.

Understanding Linux Permission Model

Each file or directory belongs to a user (owner), a group, and others. Permissions are displayed with ls -l as a 10‑character string, where the first character indicates the type ( - for regular file, d for directory, l for symlink) and the next nine characters are three triplets for user, group, and others.

drwxrwxr-x 3 user group 4096 Oct 12 13:31 example_dir

In the example, the owner and group have read, write, and execute permissions, while others have read and execute only.

chmod Syntax

$ chmod [options] mode file...

Only root or a user with sudo privileges can change permissions. Multiple files can be specified, separated by spaces.

Numeric (Octal) Mode

Permissions are summed for each class (user, group, others) using values: read = 4, write = 2, execute = 1. For example, u:rwx = 7, g:rx = 5, o:r‑ = 4 yields 754.

$ chmod 744 file.txt   # owner rwx, group r, others r
$ chmod 750 file.txt   # owner rwx, group rx, others ---
$ chmod 755 file.txt   # owner rwx, group rx, others rx

Recursive Directory Permissions

Use -R to apply changes to a directory and all its contents:

$ chmod 755 -R /path/to/dir

Symbolic Mode

Symbolic syntax uses [ugoa][+-=][rwx]. The first field selects the class (u, g, o, a). The operator + adds, - removes, and = sets exact permissions, clearing previous ones. chmod o=r file – give others read only. chmod ug+x file – add execute to user and group. chmod u=rwx,g=rw,o=r file – distinct permissions for each class. chmod o= file – remove all permissions from others.

Reference Mode

Copy permissions from a reference file with --reference=ref_file:

$ sudo chmod --reference=ref_file target_file

Special Cases

Using a capital X adds execute permission only to directories (or to files that already have execute for some class):

$ chmod a+X *

Summary

The tutorial covered the purpose of chmod, how to view permissions, numeric and symbolic representations, recursive changes, reference copying, and common pitfalls such as the effect of the = operator removing existing rights.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

securitycommand-lineUnixchmodFile Permissions
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.