How to Change File Permissions in Linux Using chmod

Unlike Windows, which often lets any user click on any file, Linux is built from the ground up with strict security in mind. Every single file and directory on an Ubuntu system is assigned specific permissions dictating who can read it, who can write to it, and who can execute it. When you get a “Permission Denied” error, knowing how to use the chmod command is essential.

Understanding Read, Write, and Execute

In Linux, permissions are broken down into three actions:

  • Read (r): The ability to view the contents of a file.
  • Write (w): The ability to modify, edit, or delete the file.
  • Execute (x): The ability to run the file as a program or script.

These actions are applied to three different groups of people:

  • User (u): The actual owner of the file.
  • Group (g): A specific group of users on the system.
  • Others (o): Everyone else.

How to Check Current Permissions

Before you change anything, you should see what the current permissions are. Open your terminal and type:

ls -l filename.txt

The output will look something like this: -rw-r--r--. This string of letters means the User has read/write (rw-), the Group has read-only (r–), and Others have read-only (r–).

Using chmod with Letters (Symbolic Mode)

The easiest way to understand chmod (Change Mode) is by using letters. You use a plus sign (+) to add a permission and a minus sign (-) to remove it.

  • Example 1 (Making a script executable): If you downloaded a python script and want to run it, you must give the User execute permission.
    chmod u+x script.py
  • Example 2 (Removing read access for others): If you have a file with passwords, you don’t want anyone else reading it.
    chmod o-r passwords.txt
  • Example 3 (Giving everyone full access): To give all users (a) read, write, and execute permissions.
    chmod a+rwx public_folder

Using chmod with Numbers (Numeric Mode)

System administrators rarely use letters. They use a faster, numeric system where the permissions are assigned a point value:

  • Read = 4
  • Write = 2
  • Execute = 1

You add the numbers together to get the total permission. For example, Read + Write = 6. Read + Write + Execute = 7.

You then provide three numbers: the first for the User, the second for the Group, the third for Others.

  • chmod 777 filename = Everyone has full Read, Write, and Execute access (4+2+1). Warning: This is a massive security risk and should rarely be used.
  • chmod 644 filename = The owner can Read and Write (6). The Group can only Read (4). Others can only Read (4). This is the standard permission for most text files.
  • chmod 755 script.sh = The owner has full access (7). Everyone else can read and execute the script, but cannot modify it (5). This is standard for programs.

Conclusion

Understanding chmod and the 644 / 755 numbering system is a fundamental rite of passage for every Linux user. It is the core mechanism that keeps Ubuntu systems secure from unauthorized tampering.

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.