Fundamentals 10 min read

Master Linux File Permissions: A Complete Guide to Using chmod

This tutorial explains Linux file and directory permissions, the chmod command syntax, numeric and symbolic modes, and provides step‑by‑step examples—including recursive changes, reference files, and selective execution—so readers can confidently manage access rights on any Unix‑like system.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux File Permissions: A Complete Guide to Using chmod

Understanding Linux Permissions

Linux determines file and directory accessibility through ownership (user, group, others) and three basic rights: read (r), write (w), and execute (x). Permissions can be expressed textually (e.g., rw-r--r--) or numerically using octal values.

Viewing Current Permissions

Use ls -l to list files with detailed attributes. The first character indicates the type ( - for regular file, d for directory, l for symlink). The next nine characters are three triplets representing user, group, and others permissions.

ls -l output example
ls -l output example

chmod Syntax

The basic form is chmod [options] mode file.... Only root or users with sudo can change permissions on files they do not own.

Numeric (Octal) Mode

Assign permissions with three (or rarely four) digits. Each digit is the sum of read = 4, write = 2, execute = 1 for the corresponding class.

Read → 4

Write → 2

Execute → 1

Example: chmod 754 file gives user rwx (7), group rx (5), others r (4).

$ chmod 744 www.linuxmi.com.txt
$ chmod 750 www.linuxmi.com.txt
$ chmod 755 linuxmi.txt

Recursive Directory Changes

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

$ chmod 755 -R /home/linuxmi/linux

Symbolic (Text) Mode

Modify permissions with symbolic expressions: [ugoa][+-=][rwx]. The u, g, o, a selectors target user, group, others, or all. + adds, - removes, = sets exactly. $ chmod u=rwx,g=rw,o=r filename Omitting the selector defaults to a. Using = without specifying permissions clears that class.

Selective Permission Examples

Give others read permission only: $ chmod o=r file Add execute permission for user and group: $ sudo chmod ug+x linuxmi.txt Remove all permissions from others:

$ sudo chmod o= file

Reference File Mode

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

$ sudo chmod --reference=www.linuxmi.com.py linuxmi.txt

Applying Execute Only to Directories

Use capital X to add execute permission only to directories:

$ chmod a+X *

Conclusion

The chmod command offers flexible ways to control access to files and directories, whether using numeric octal values, symbolic expressions, recursive options, or reference files. Mastering these techniques is essential for secure and efficient system administration.

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.

Sysadmincommand-linechmodfile-permissions
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.