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.
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_dirIn 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 rxRecursive Directory Permissions
Use -R to apply changes to a directory and all its contents:
$ chmod 755 -R /path/to/dirSymbolic 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_fileSpecial 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
