How to Use the chmod Command in Linux to Change File Permissions

Security in Linux is fundamentally based on file ownership and permissions. Every file and directory on a Linux system is governed by strict mathematical rules dictating exactly who is allowed to read it, write to it, or execute it as a program. If a downloaded script throws a \”Permission denied\” error, or if you need to lock down a sensitive configuration file so other users cannot alter it, you must modify these access rules. To do this, Linux administrators use the chmod (change mode) command.

Why Use the chmod Command?

The chmod command directly manipulates the read (r), write (w), and execute (x) flags associated with a file. It allows you to define these permissions across three distinct classes: the Owner of the file, the Group associated with the file, and Others (everyone else on the system). Without chmod, you cannot run custom bash scripts, secure private SSH keys, or safely share directories in a multi-user server environment.

Step 1: Understand the Symbolic Mode

The easiest way to use chmod is through \”symbolic mode,\” which uses letters to represent the classes and permissions.

  • Classes: u (user/owner), g (group), o (others), a (all).
  • Operators: + (add permission), - (remove permission), = (set exact permission).
  • Permissions: r (read), w (write), x (execute).

Step 2: Make a File Executable

The most common use of chmod is granting execution rights to a newly created script.

  1. Open your Linux terminal.
  2. To allow the owner (user) to execute a script named backup.sh, run:
chmod u+x backup.sh

Now, the owner can run the script using ./backup.sh without encountering a \”Permission denied\” error.

Step 3: Remove Permissions

You can revoke access just as easily to secure sensitive data.

  1. Suppose you have a file named passwords.txt and you want to ensure no one else on the system can read or edit it. Run:
chmod go-rw passwords.txt

This explicitly removes (-) the read (r) and write (w) permissions from the group (g) and others (o).

Step 4: Understand the Absolute (Numeric) Mode

System administrators often prefer \”absolute mode,\” which uses a three-digit mathematical code to set all permissions instantly. Each permission is assigned a number: Read = 4, Write = 2, Execute = 1. You add these together for each class (Owner, Group, Others).

  1. chmod 777 file.txt: Grants full read/write/execute access to everyone. (Highly insecure, rarely recommended).
  2. chmod 644 file.txt: The standard file permission. The owner can read and write (4+2=6). The group and others can only read (4).
  3. chmod 755 script.sh: The standard executable permission. Owner has full access (7). Group and others can read and execute (4+1=5) but cannot edit the script.

By mastering the chmod command, Linux administrators maintain strict control over system security, ensuring that files are accessible only to authorized personnel while remaining protected against unauthorized modification.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.