Linux permissions allow you to set security levels for different users. Linux allows you to define access levels for individual files, specify attributes, and tighten security. This way you can provide granular permission levels and improve file security.

Linux lets you choose from different file permissions for each type of user, but they can generally include a combination of:

  • Read 
  • Write
  • Execute

Before we talk about Linux file permissions, let’s talk about the different types of users. 

Linux Users 

The three types of users include:

  • Owners
  • Groups
  • Others 

Owner

The owners include those who create the file. 

Group

Groups generally include different users with the same Linux permissions. For instance, the owner can provide read information to a specific group instead of manually granting permission to each user. 

Others

This includes any other user who can access the file. These are generally users who haven’t created the file, nor are part of a group with specific permissions. So, if you’ve set permissions for “others”, they will apply to this group. 

Understanding Linux Permissions

Now, as mentioned above, each file or directory can be assigned any of the three permissions discussed below.

Read (r)

The Read permission gives users the ability to open and read a file. If the Read permission is assigned to a directory, users will be able to list all of its contents. 

Write (w)

The Write permission lets users modify the contents of a directory or a file. This allows a user to add, remove, rename, or modify the file however they see fit. 

For instance, if you have to write permissions for a file, but not for the directory, you won’t be able to rename or remove the file from the directory. You’ll only be able to make changes to the contents of the file itself. 

Execute (x)

This allows the user to execute the file. Essentially, with this permission, you can run the file.  

Example of Linux Permissions

For instance, if the file name is:

Ls -l example_file

The first character tells you about the type of file. It could either be a directory (d), a regular file (-), or a symbolic link (l). The output of this file provides the following permissions:

-rw-w-r- 

In the first part, you can see that the file owner has both the read and write permissions. Then, the group only has write permission, and all others have just read permission. 

How to Change Linux File Permissions

The chmod command is commonly used to change Linux file permissions. Any user with sudo privileges, the root, and the file owner are capable of changing the file permissions. When using the symbolic format, here’s the format that you can use to change the file permission:

chmod [OPTIONS] [ugoa] [-+=] perms...[,...] filename...

In this format, the first set of flags simply denotes the user classes for which you want to change the permissions. These include:

  • The owner (u)
  • Group (g)
  • Other users (o)
  • All users (a)

The next set of flags defines whether to add (+), remove (-), or change the existing permissions to specific permissions (=). 

For example, if the command is:

chmod -r o-x example_file  

It will remove the execute permission for all other users.

Absolute Mode

Also known as the numeric mode, file permissions in this mode are represented by a three-digit number instead of a series of characters. Here are the numerical values for your understanding:

0 = No permission

1 = Execute

2 = Write

3 = Execute and Write

4 = Read

5 = Read + Execute

6 = Read + Write

7 = Read + Write + Execute

So, if you were to use the following command:

chmod 754 example_file

You’ll essentially be changing the file permissions to the following:

  • Owner: Read, write, and execute (7)
  • Group: Read and execute) (5)
  • All others: Can read) (4)

Conclusion

We hope you find this simple guide for Linux permissions helpful. Keep in mind that the chmod command lets you change permissions, as long as you’ve sudo privileges or are the file owner. Any questions about Linux you’d like to see us cover in a future guide? Feel free to join the conversation by dropping a comment below or Tweeting at us! 💬