How to Change File Permissions in Ubuntu Terminal

Linux is fundamentally designed as a multi-user operating system. If you run a web server, you might have one user account for yourself, one for the database, and one for the web application itself. To prevent the web application from accidentally overwriting your personal files, Ubuntu relies on a strict system of “File Permissions.”

Every file and folder has three levels of access: Read (can view it), Write (can edit it), and Execute (can run it as a program). If you download a new bash script from the internet, you will often find that it refuses to run, throwing a “Permission Denied” error. You must manually grant the file the correct permissions using the terminal.

Understanding the ‘chmod’ Command

The utility used to change file permissions in Linux is called chmod (change mode).

While permissions can be written using letters (like +rwx), most Linux administrators use the numerical (octal) system, as it is much faster to type. The system uses a three-digit number to assign permissions to three different groups: the Owner, the Group, and Everyone Else.

The numbers are calculated like this:

  • 4 = Read
  • 2 = Write
  • 1 = Execute
  • 0 = No permissions

You simply add the numbers together to create the permission level. For example, Read (4) + Write (2) = 6.

How to Change Permissions (Practical Examples)

Open your terminal and navigate to the directory containing your file. Let’s assume you have a file named script.sh.

1. Making a Script Executable

If you want the owner to have full control (Read, Write, Execute = 7), the group to be able to read and execute (Read, Execute = 5), and everyone else to only be able to read (Read = 4), you would type:

chmod 754 script.sh

2. Making a File Completely Private

If you have a file containing sensitive passwords, you want the owner to have read and write access (6), but you want to completely block everyone else from even looking at it (0 and 0). You would type:

chmod 600 passwords.txt

3. Making a File Publicly Writable

If you have a log file that multiple different applications need to dump data into, you might want to give absolute full control to everyone on the server (Read, Write, Execute = 7 for all groups). You would type:

chmod 777 error.log

Warning: Using 777 is a massive security risk. Only use it for temporary debugging on non-critical files, as it allows any user or program on the server to modify or delete the file.

How to Check Your Changes

To verify that your chmod command was successful, use the list command with the long-format flag:

ls -l

Look at the far left column of the output. You will see a string of ten characters (like -rwxr-xr--). This visually confirms exactly who has permission to read, write, and execute your file.

Get the best tech tips delivered straight to your inbox.

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