How to Change File Permissions in Linux (chmod)

Linux is designed from the ground up as a multi-user operating system. Because multiple people can theoretically log into the same server simultaneously, Linux relies on a strict permission system to ensure that User A cannot accidentally (or maliciously) delete a critical file belonging to User B.

Every single file and folder on a Linux machine has three distinct levels of access:

  1. Read (r): Can the user look at the contents of the file?
  2. Write (w): Can the user edit or delete the file?
  3. Execute (x): Can the user run the file as a program or script?

If you download a bash script from the internet, Linux will automatically block you from running it because the file lacks “Execute” permissions. To fix this, you must change the file’s permissions using the chmod (change mode) command.

The Simple Method (Symbolic Mode)

The easiest way to use chmod is to use letters and mathematical symbols. This method is highly intuitive for beginners.

First, you define who you are giving permissions to:

  • u (User): The person who owns the file.
  • g (Group): Other users who are in the same administrative group as the owner.
  • o (Others): Everyone else on the server.
  • a (All): Applies the change to all three categories simultaneously.

Next, you use a + (plus) to add a permission, or a (minus) to take a permission away.

Finally, you specify the permission (r, w, or x).

Practical Examples

Imagine you have a file named script.sh.

  • Goal: You want to make the script executable for yourself (the owner).
    • Command: chmod u+x script.sh
  • Goal: You want to stop anyone else from editing a sensitive document. You must take away (minus) their write (w) access.
    • Command: chmod o-w document.txt
  • Goal: You want to give everyone on the server the ability to read and execute a file, but not write to it.
    • Command: chmod a+rx file.txt

The Advanced Method (Numeric Mode)

If you read Linux documentation or follow server tutorials online, you will rarely see the symbolic letters used. Instead, system administrators use a three-digit numbering system (like chmod 755 or chmod 644). This numeric mode is much faster to type once you understand how the math works.

Each permission is assigned a specific number value:

  • Read (r) = 4
  • Write (w) = 2
  • Execute (x) = 1

To grant multiple permissions, you simply add the numbers together. For example, if you want someone to have Read (4) and Write (2) access, the number is 6. If you want them to have total access (Read, Write, and Execute), the number is 7.

A numeric chmod command always consists of exactly three numbers. The first number represents the User (Owner), the second number represents the Group, and the third number represents Others.

Common Numeric Examples

  • chmod 777 filename
    • Meaning: Absolute chaos. 7 (Owner), 7 (Group), 7 (Others). Every single person on the computer has total power to read, edit, and execute this file. This is a massive security risk and should almost never be used.
  • chmod 755 filename
    • Meaning: The standard for executable scripts and web directories. The Owner has total control (7). The Group and Others can read and execute the file (4 + 1 = 5), but they cannot edit or delete it.
  • chmod 644 filename
    • Meaning: The standard for basic text files and HTML documents. The Owner can read and write (4 + 2 = 6). Everyone else can only read it (4). Nobody can execute it.

By mastering these numbers, you can instantly configure complex permissions with a single command.

Get the best tech tips delivered straight to your inbox.

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