How to Change File Permissions on Ubuntu

Linux is built from the ground up as a multi-user operating system. If you download a bash script and the system says “Permission denied” when you try to run it, or if your web server cannot display a specific HTML file, you are experiencing Ubuntu’s strict file security in action.

Every file in Ubuntu has three distinct types of permissions (Read, Write, and Execute) assigned to three different categories of people (the Owner, the Group, and Everyone Else). Here is how to understand and change file permissions on Ubuntu using the chmod command.

Understanding Linux Permissions

Before you type any commands, you must understand what you are actually changing. If you type ls -l in your terminal, you will see a strange string of letters next to your files, looking something like this: -rw-r--r--.

This string is broken into three chunks of three letters (after the first dash):

  • r = Read (Permission to open and view the file).
  • w = Write (Permission to edit, modify, or delete the file).
  • x = Execute (Permission to run the file as a program or script).

The first chunk (rw-) is what the Owner can do. The second chunk (r–) is what the Group can do. The third chunk (r–) is what Others (anyone else on the server) can do. In this example, the owner can read and write, but everyone else can only read.

Method 1: Symbolic Mode (Easiest to Learn)

The symbolic mode of chmod uses simple letters and math symbols (+, -, =) to add or remove permissions.

  • u = User (Owner)
  • g = Group
  • o = Others
  • a = All (Everyone)

Examples:

  • To give the owner permission to execute a script named script.sh:
    chmod u+x script.sh
  • To remove write permission from “Others” for a file named report.txt:
    chmod o-w report.txt
  • To give absolutely everyone read and write permission to a file:
    chmod a=rw public_doc.txt

Method 2: Numeric (Octal) Mode (The Professional Way)

System administrators rarely use the letters. Instead, they use a three-digit number system. Each permission is assigned a numerical value:

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

You simply add the numbers together for each chunk (Owner, Group, Others).

Examples:

  • chmod 755 script.sh: The Owner gets 4+2+1=7 (Read, Write, Execute). The Group gets 4+0+1=5 (Read, Execute). Others get 4+0+1=5 (Read, Execute). This is the standard permission for a script.
  • chmod 644 report.txt: Owner gets 4+2=6 (Read, Write). Group gets 4 (Read only). Others get 4 (Read only). This is the standard permission for a normal text file.
  • chmod 777 public_folder: Everyone gets absolutely every permission (4+2+1). Warning: This is incredibly dangerous and should almost never be used on a production server.

If you are modifying a file owned by the “root” user, remember that you must place the sudo command before any of these chmod commands to elevate your privileges.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

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

Receive our best articles and tips delivered straight to your inbox.