Mastering Linux File Permissions: Read, Write, and Execute
Linux+ · Security · By Super Admin
Understand the three permission types in Linux and how they apply to owners, groups, and others for files and directories.
The Three Permission Types
Linux uses three types of permission controls to manage access to files and directories. The read permission grants the ability to access the data stored within the file or directory, allowing users to view file contents or list directory contents. The write permission grants the ability to modify the data stored within the file or directory, enabling users to change file contents or create and delete files within a directory. The execute permission grants the ability to run the file on the system, or the ability to list the files contained in the directory, which is essential for both executable programs and directory traversal. These three permission types form the foundation of Linux access control, and understanding how they function is critical for managing system security effectively.
Each permission type has different implications depending on whether it is applied to a file or a directory. For files, read permission allows viewing the file contents, write permission allows modifying the file, and execute permission allows running the file as a program. For directories, read permission allows listing the files contained in the directory, write permission allows creating and deleting files within the directory, and execute permission allows accessing files within the directory and listing its contents. This distinction between file and directory permissions is important because the same permission names have slightly different meanings depending on the object type.
Permission Structure and Display Format
You can assign each tier of protection—owner, group, and other—different read, write, and execute permissions, creating a set of nine different permissions that are assigned to each file and directory on the Linux system. The nine permissions appear in the ls output as the first column of information when you use the -l option, displayed in a specific order that represents owner permissions, group permissions, and other permissions. The first character denotes the object type, with a dash indicating a file and a d indicating a directory. The next three characters denote the owner permissions in the order of read, write, and execute, with a dash indicating the permission is not set and the r, w, or x indicating the read, write, or execute permission is set.
<img src="/question_assets/Linux+/sg_c15f001.png" alt="Illustration of file and directory permissions depicts read, write, and execute categories for Owner, Group, and Others."/>
<figcaption>File and directory permissions as displayed in the ls output</figcaption>
The image above shows how the nine permission bits are organized in the ls output, with three characters each for owner, group, and others permissions. The second set of three characters denotes the group permissions for the file or directory, again using the read, write, and execute order with a dash indicating the permission is not set. Finally, the third set of three characters denotes the permissions assigned to user accounts that are not the owner or a member of the group assigned to the file or directory, using the same read, write, and execute order. This consistent structure makes it easy to read and understand the complete permission set for any file or directory on the system.
Modifying Permissions with chmod
Either the root user account or the owner of the file or directory can change the assigned permissions by using the chmod command. The chmod command uses two different modes for denoting the read, write, and execute permission settings: symbolic mode and octal mode. In symbolic mode, you denote permissions by using a letter code for the owner (u), group (g), others (o), or all (a) and another letter code for the read (r), write (w), or execute (x) permission, separated with a plus sign (+) to add the permission, a minus sign (-) to remove the permission, or an equals sign (=) to set the permission as the only permission. Octal mode represents the nine permission bits as three octal numbers, one each for the owner, group, and other permissions, allowing you to set all permissions in a single command.
Discussion (0)
No discussion on this article yet — be the first to comment.
Please sign in to join the discussion.