FUNDAMENTALS A Complete Guide for Beginners
While running commands in Linux have you ever come across an error message saying the “folder: permission denied”? This is because the Linux operating system by default sets access permissions to the folders which are not accessible to all the available users. This is done by the operating system to ensure optimum security. But we often need to change such restrictions for performing necessary tasks. Therefore, in this article, I will discuss different ways of how to change folder permissions in Linux.
Key Takeaways
- Two different ways to change folder permissions in Linux.
- Getting familiar with the sudo, chmod, ls commands in Linux.
- Running commands as root user.
Requirements
- Need to be a root user or have root/sudo privileges to change the permissions of folders owned by other users in Ubuntu.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Permission Modes
From the Linux CLI, changes in folder permissions are achieved by using the chmod command. The altered permissions can be represented either in symbolic mode or in absolute mode. Applying Symbolic mode you can change permissions for any desired user class. Whereas with Absolute mode you have to set permissions for all types of user class separately.
Below you will find detailed information on each of the modes.
A. Symbolic Mode
Using symbolic mode, you can add, remove or set access permissions for a particular user class with logical operators. Since chmod takes multiple sets of symbols as arguments, changing permissions of multiple user classes requires comma (,) separated logical expressions.
User Class | Operator | Access Type |
---|---|---|
u (user) | + (add access) | r (read) |
g (group) | – (remove access) | w (write) |
o (other) | = (set exact access) | x (execute) |
a (all classes: u, g, and o) |
B. Absolute Mode
On the other hand, in absolute mode, to remove all permissions you can assign a “0” (zero) or, to give permissions you must assign one of the following octal values for each user class.
Permissions | Read
(r) |
Write
(w) |
Execute
(x) |
Read
& Write (r+w) |
Read
& Execute (r+x) |
Write
& Execute (w+x) |
ALL
( r+w+x) |
---|---|---|---|---|---|---|---|
Octal value | 4 | 2 | 1 | 6
(= 4+2) |
5
(= 4+1) |
3
(= 2+1) |
7
(= 4+2+1) |
Watch to Change Folder Permissions in Linux
2 Methods to Change Folder Permissions in Linux
In Ubuntu, you can change folder permissions either from the CLI(Command Line Interface) or from the GUI(Graphical User Interface). In this article, I will demonstrate both of the main approaches of changing folder permission Linux.
Method 01: Using CLI to Change Folder Permissions in Linux
Case A: Changing User’s Own Folder Permissions
You can change your own folder’s permissions by simply running the chmod command. You may use either the symbolic mode or the absolute mode of permissions to achieve this task.
In this example, I will change the permissions of the “Documents” folder in my home directory. You can see in the following image, the “Documents” folder does not have write and execute access to other users. I will change this permission to give read, write, and execute access to everyone. In this case, using the symbolic mode of the chmod command, I will be adding only write access to the group user class. For the other user class, I will need to add both write and execute access. If you want to use the absolute mode, you have to set permissions to octal value 7 for all the available users.
Steps to Follow >
➊ At first, press CTRL+ALT+T to open the Ubuntu Terminal.
➋ After that, copy any of the following commands:
chmod g+w,o+wx Documents
Or,
chmod 777 Documents
- chmod: Changes folder permissions.
- g+w: Adds write access for the group user class.
- o+wx: Adds write and execute access for the other user class.
- 777: Sets read, write and execute permissions to all user classes.
- Documents: Name of the folder.
➌ Then, press the ENTER button.
➍ Now, to check the updated permissions run the command below:
ls -l
➎ Then, hit ENTER.
As a result of the given steps, in the above image, you can see that I have given permission to read, write and execute the “Documents” folder to every user class. Moreover, you can view the current permission status by typing the ls command with -l option.
- How to Give Permission to User in Linux? [4 Methods]
- 2 Ways to Change Folder Permissions from Root to User in Linux
Case B: Changing Other User’s Folder Permissions
When you are a root user or you possess sudo privileges as the root user, you will be able to change the permissions of folders owned by other users as well. In this case, using the sudo keyword you can run the chmod command on these file paths even if the group and other permissions are omitted.
Here, I will change the permissions of the “docs” folder owned by another user named “other_user”. You can see in the image below, that the desired directory resides in the path “/home/other_user” and it has read, write and execute permissions only for the owner.
Follow the given instructions to change the permissions of the folder.
Steps to Follow >
➊ At first, press CTRL+ALT+T to open the Ubuntu Terminal.
➋ After that, copy the following command:
sudo chmod 777 /home/other_user/docs
Or,
sudo chmod a+rwx /home/other_user/docs
- sudo: Grants administrative privileges.
- chmod: Changes folder permissions.
- 777: Sets read, write and execute permissions to all user classes.
- a+rwx: Adds read, write, and execute permissions for all user classes.
- /home/other_user/docs: Path to the desired folder.
➌ Then, press the ENTER button.
➍ Now, to check the updated permissions run the command below:
sudo ls -l /home/other_user
➎ Then, hit ENTER.
In the above image, you can see that I have changed the “docs” folder permission owned by another user the “other_user”. Furthermore, by typing the ls command with sudo and the absolute path of the folder, you can view the updated permissions.
Method 02: Using GUI to Change Folder Permissions in Linux
You can also change a folder’s permissions from GUI( Graphical User Interface). But with this approach, you will not be able to apply every combination of the read, write and execute access. To clarify, the folder permissions available to set from the GUI are listed below.
Permission Options | Access Type |
---|---|
List files only | Read-only (r) |
Access files | Read & Execute (r+x) |
Create and delete files | ALL ( r+w+x) |
None | No access |
Steps to Follow >
➊ At first, select your desired folder you want to change permissions of and Click the Right Mouse Button. At this time, Click on “Properties” from the available options.
➋ Subsequently, go to the “Permissions” section of the Folder Properties.
❸ There are individual options to change permissions of owner, group, and other user classes. For instance, I will leave the owner’s access permissions as it is and SELECT the group access to change it.❹ Furthermore, I will change the group permissions to Access files.❺ Now, you can see that the other user class does not have any access to the folder. Therefore, to change it I will SELECT the other access option.❻ Moreover, I will set the other access to List files only.❼ Then, I will close the Documents Properties tab.
Finally, upon completion of the mentioned steps, you will find the permissions of the folder changed as shown in the image above.
- How to Change File Permissions to 777 in Ubuntu?
- 2 Ways to Change Folder Permissions Recursively in Linux
Comparative Analysis of Methods
Since this article introduces multiple methods for a single task, you might get confused about which one to pick. Therefore, in this section, I am presenting a comparative analysis of the two different approaches for your convenience. You can learn the advantages and disadvantages of the available methods and choose which is the best for you.
Methods | Pros | Cons |
---|---|---|
Method 1 |
|
|
Method 2 |
|
|
Summing up it can be said that both methods come with their own pros and cons. To emphasize, the suitable method varies from user to user. If you want to apply a variety of permission changes and feel comfortable with the CLI you can go for Method 1. On the other hand, If you do not have any idea about the Linux commands and the limited permission options work for you, then you can use the approach through GUI.
Conclusion
To conclude, I have presented you with the possible ways of changing folder permissions in this article. It includes feasible approaches from both CLI and GUI. Furthermore, I have also illustrated the method of changing folder permissions that are owned by another user. I hope following this guide will help you through your journey with the command line and make you a power user of Linux.
People Also Ask
Related Articles
- How to Change Permissions of All Files in a Folder in Linux?
- Manage File Permissions in Ubuntu Using Command?
- How to Change File Permissions in Linux? [6 Examples]
- 2 Cases to Give User Permission to Folder and Subfolders in Ubuntu
- How to Change Directories and Files Recursively with “chmod”
- Change Permissions on Mounted Drive in Linux