Managing Basic Permissions. File Permissions in Linux/Unix: How to Read/Write & Change? Understanding Linux File Permissions is the aim of writing this article. After reading this post, you will learn how to also change directory permissions in Linux. In other explanations, this is also known as Unix / Linux – File Permission / Access Modes. While you continue to read from this page, you will get free access to How to Use the chmod Command on Linux too.
Other Courses
- Top Kubernetes Courses Online – IT & Software Development [Udemy]
- 10 Free Kubernetes Courses Online Tutorials [Udemy]
- Linux Operating Systems for Kubernetes – OS Support
- Container 101 Tutorials: Kubernetes Technology
- 10 Best Udemy Kubernetes Courses & Tutorials [2021]
Linux File Permissions deep dive — Part 1
The permissions for Linux files and directories are separated into three tables, each with three permissions (read, write, and execute) clustered for three different types of files and directories (users, groups and others)
At the beginning, there is also an additional column that will show whether it is either a directory or a connection.
![Linux directory or a link - Linux File Permissions](https://hybridcloudtech.com/wp-content/uploads/2021/02/Linux-directory-or-a-link.png)
Take a look at the sample output of ls -l command: available at https://linux.die.net/man/1/ls.
![Here’s a sample output of ls -l command: - Linux File Permissions](https://hybridcloudtech.com/wp-content/uploads/2021/02/Heres-a-sample-output-of-ls-l-command.png)
Now, lets go ahead to break it up for better to understanding:
![Linux read and write command - Linux File Permissions](https://hybridcloudtech.com/wp-content/uploads/2021/02/Linux-read-and-write-command.png)
Note that it is important to note that while these three permissions are added to files or folders, because they vary.
![Linux Permission Sample - Linux File Permissions](https://hybridcloudtech.com/wp-content/uploads/2021/02/Linux-Permission-Sample.png)
Register Courses for this Year
- Coursera Cyber Security Courses Online Free and Paid Classes
- 15 Best Cyber Security Courses | Coursera Online Free Training
- 10 Free Kubernetes Courses Online Tutorials [Udemy]
How to Use the chmod Command in Linux
You use the chmod command to set permissions for user (u), community (g), and others (read, write, and execute) (o). For reference purposes, a few examples are shown below:
Grants execute permission to user.
![chmod file](https://hybridcloudtech.com/wp-content/uploads/2021/02/chmod-file.png)
Grants read to user and execute to group.
![Grants read to user and execute to group.](https://hybridcloudtech.com/wp-content/uploads/2021/02/Grants-read-to-user-and-execute-to-group..png)
Revokes read and execute from user.
![Revokes read and execute from user.](https://hybridcloudtech.com/wp-content/uploads/2021/02/Revokes-read-and-execute-from-user..png)
Grants execute for user, group and other.
![Grants execute for user, group and other.](https://hybridcloudtech.com/wp-content/uploads/2021/02/Grants-execute-for-user-group-and-other..png)
In addition, Linux permission also have a numerical value associated with each of them which makes it easy to refer and manipulate for each roles.
Few examples:
![Linux File Permissions sample](https://hybridcloudtech.com/wp-content/uploads/2021/02/Grants-rx-to-user-and-r-to-groups-and-others..png)
Grants r,x to user and r to groups and others.
![Grants r,x to user and r to groups and others.](https://hybridcloudtech.com/wp-content/uploads/2021/02/Grants-rx-to-user-and-r-to-groups-and-others.-1.png)
Grants r,w,x to user, w to group and nothing to others
![Grants r,w,x to user, w to group and nothing to others](https://hybridcloudtech.com/wp-content/uploads/2021/02/Grants-rwx-to-user-w-to-group-and-nothing-to-others.png)
The Venn diagram shown below gives a good perspective of the numerical values for easy referencing.
![Venn diagram gives a good perspective of the numerical values for easy - Linux File Permissions](https://hybridcloudtech.com/wp-content/uploads/2021/02/Venn-diagram-gives-a-good-perspective-of-the-numerical-values-for-easy.png)
Certifications
- 2021 Best Salary Paying IT Certifications in-Demand
- Microsoft Certifications with Highest Salary in Demand 2021
- Most in-Demand IT Certifications for Beginners & Pros
Recursive eXecute permission for only directories and not files:
Listen carefully. If you remember from the beginning of this post, when set to a directory, execute permission allows you to enter/access it, while setting execute permission on a file causes it to run like a programme or script. By design, a directory generated on the Linux filesystem has execute privileges, allowing for directory traversal.
There might be instances, though, where this may be absent and you will need to set execute permissions on all files and sub-folders. Sure, you might use the chmod command’s -R (recursive) option to accomplish this.
![chmod 1](https://hybridcloudtech.com/wp-content/uploads/2021/02/chmod-1.png)
Explanation continues. What the above command does is to recursively set the execution permission not only for all sub-folders but also for all directories (a potentially dangerous situation). It’s only important to set it for the directories and not for any of the files.
![chmod 2](https://hybridcloudtech.com/wp-content/uploads/2021/02/chmod-2.png)
It means that files do not get execute authorisation with X (uppercase), unless the file has already configured it, which makes it a more intelligent way to deal with execute permissions.
Conclusion:
In conclusion, I hope this article has offered some insight into dealing with Linux’s simple file/directory permissions. In the comments section, please let me know your suggestions (bouquets and brickbats).
Update: Part 2 of this series is available, which addresses advanced Linux permissions (SUID, SGID & Sticky Bit).
Trending IT & Business Courses
- 16 Best Ethical Hacking Courses on Udemy in 2021
- [Udemy] 15 Best SQL Courses and Certifications 2021
- Top Best Android Development Courses on Udemy [2021]
- IIBA Certifications – International Institute of Business Analysis
- IIBA Specialized Business Analysis Certifications Guide
- Top IIBA Core Business Analysis Certifications Guide