Master Linux File Permissions: A Complete Guide to Using chmod
This tutorial explains the Linux chmod command, covering the permission model, how to view permissions with ls -l, numeric and symbolic notations, recursive changes, reference files, and multiple practical examples to help you manage file and directory access securely.
What is chmod?
The chmod (change mode) command modifies file and directory permissions on Linux/Unix systems, controlling which users can read, write, or execute a given object.
Linux permission model
Each file or directory belongs to an owner (user), a group, and others. Permissions are expressed as read ( r), write ( w), and execute ( x) for each of these three categories. u – owner permissions g – group permissions o – others permissions
Viewing permissions
Use ls -l to list files with their permission strings. The first character indicates the type ( - regular file, d directory, l symlink). The next nine characters are three groups of rwx triples.
linuxmi@linuxmi:~/www.linuxmi.com$ ls -lNumeric (octal) notation
Permissions can be set with a three‑digit (or four‑digit) octal number where each digit is the sum of read = 4, write = 2, execute = 1.
Read → 4
Write → 2
Execute → 1
Example: owner rwx = 7, group rx = 5, others r‑ = 4 → 754. $ chmod 754 filename Common shortcuts:
$ chmod 744 file.txt # rwx for owner, r-- for group & others $ chmod 750 file.txt # rwx for owner, r-x for group, --- for others $ chmod 755 file.txt # rwx for owner & group, r-x for othersSymbolic notation
Symbolic mode uses [ugoa][+-=][rwx] to modify specific classes. $ chmod u+rwx,g=rw,o=r filename Operators: + – add permission - – remove permission = – set exact permission (clears previous)
Common examples
Assign read permission only to others:
$ chmod o=r file.txtAdd execute permission for owner and group:
$ sudo chmod ug+x file.txtSet different permissions for each class:
$ sudo chmod u=rwx,g=rw,o=r filenameRemove all permissions from others (equivalent forms): $ sudo chmod o= filename or
$ sudo chmod o-rwx filenameRecursive changes
Use -R to apply permissions to a directory and all its contents.
$ chmod -R 755 /path/to/dirCopy permissions from a reference file
The --reference option copies the mode of a template file to the target.
$ sudo chmod --reference=ref_file target_fileApply execute permission only to directories
Uppercase X adds execute permission only to directories.
$ chmod a+X *Summary
The chmod command provides flexible ways to view and modify file and directory permissions using numeric or symbolic notation, recursive options, and reference files, enabling precise access control in Linux environments.
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.
