A Comprehensive Guide to Linux File Permissions: Read, Write, Execute

Amit Kumar
4 min readFeb 8, 2024

Linux file permissions play a pivotal role in determining the level of access and control users have over files and directories within the operating system. These permissions, categorized as read, write, and execute, form the foundation of security measures in Linux environments. Understanding and effectively managing file permissions is essential for maintaining the integrity and confidentiality of data. In this comprehensive guide, we will delve into the intricacies of Linux file permissions, providing a clear and concise overview of how users can navigate and leverage these permissions to secure their files and directories.

File Permissions

  • r — Read permission is used to access the file’s contents.
  • w — Write permission allows you to modify or change the contents of a file.
  • x — Execute permission allows you to execute the contents of a file.

Directory Permissions

  • r — Allows the contents of the directory to be listed if the x attribute is also set.
  • w — Allows files within the directory to be created, deleted, or renamed if the x attribute is also set.
  • x — Allows a directory to be entered (i.e. cd dir).

How to see the file permissions?

To see the file permissions, you can long list the files and directories using ls command along with -l flag.

ls -l

Here, the first column shows all the permissions of the file. “-” indicates that this permission is not given.

Three Permission Groups

  1. Owners: These permissions apply exclusively to the individuals who own the files or directories.
  2. Groups: Permissions can be assigned to a specific group of users, impacting only those within that particular group.
  3. All Users: These permissions apply universally to all users on the system, presenting the highest security risk. Assigning permissions to all users should be done cautiously to prevent potential security vulnerabilities.

Operators for Changing File Permissions

Changing the File Permissions

You can use the “chmod” command to change the file permissions because the nine security characters are collectively called the security “mode” of the file.

For example, if you want to give “execute” permission to the world (“other”) for file “xyz.txt”, you can run:

chmod o+x xyz.txt

Another example can be this: If you want to add read(r) and write(w) permission to both user(u) and group(g) and revoke execute(x) permission from others(o) for the file abc.mp4.

chmod ug+rw,o-x abc.mp4

If you want to revoke all the read(r), write(w), and execute(x) permission from all user(u), group(g), and others(o) for the file xyz.txt, you can run:

chmod ugo-rwx xyz.txt

If you want to assign read(r) and execute(x) permission to both user(u) and group(g) and add read permission to others for the file abc.c.

chmod ug=rx,o+r abc.c

Octal Representation of File Permissions or Mode

Using the octal notations table instead of ‘r’, ‘w’, and ‘x’. Each digit octal notation can be used for either of the group ‘u’, ‘g’, or’o’.

If you want to provide full read write and execute permission (code=7) to all the group, you can run any of these codes.

chmod ugo+rwx file_name
chmod 777 file_name

Similarly, both the codes mentioned below give read (code=4) user permission, write and execute (code=3) for the group and read and execute (code=5) for others.

chmod u=r,g=wx,o=rx file_name
chmod 435 file_name

In conclusion, understanding Linux file permissions is crucial for maintaining data security. By grasping the concepts of read, write, and execute permissions, users can confidently control access to files and directories. This guide provides a solid foundation for navigating these permissions, empowering you to enhance the security and stability of your Linux system. As you apply these principles in practice, you’ll gain valuable insights into effective security practices, ensuring a well-managed computing environment. Embrace this knowledge to fortify your Linux experience with heightened control and confidence.

--

--

Amit Kumar

🚀 BTech student diving into code and tech wonders. Exploring the digital realm, one line at a time. Join me on this tech journey! 💻✨ #TechExplorer