In a multiuser system like Ubuntu, permission is a vital part of the system to prevent unauthorized access to the system files and directories. Moreover, It makes the whole system more secure. Different users possess different types of permission for the system. Therefore, It is necessary to know how to give user permission to folder and subfolders in Ubuntu.
Key Takeaways
- Learning 2 approaches to give permission to folders and subfolders.
- Getting familiar with sudo, ls, chmod, and a few other commands in Linux.
Requirements
- Need to be a root user or have root/sudo privileges to change the permission of the folder and subfolder of other users in Ubuntu.
Downloads
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Types of Permission
In a multiple-user system, some users may need special permission on a special folder and subfolder. You can change permission from the terminal following symbolic mode or absolute mode. Symbolic mode follows the octal number system.
Permission Format: (d/-)rwx—rw-
- “d” means directory and “–” means file.
- rwx: The 1st three characters represent permission for the owner.
- —: The 2nd three characters represent permission for the group.
- rw-: The last three characters represent permission for other users.
Some types of symbolic modes are given below.
User Class | Operator | Access Type |
---|---|---|
User | +(add permission) | r(read) |
Group | -(remove permission) | w(write) |
Other | =(set access ) | x(execute) |
a (all class: u, g, o) | – (no permission to read, write or execute) |
For the absolute mode, you have to use an octal number system. Some types of absolute modes are given below.
Permission Mode | 4(Read) | 2(Write) | 1(Execute) | Command |
---|---|---|---|---|
No reading, Writing or Executing permission | No | No | No | 0 |
Only Execute | No | No | Yes | 1 |
Only Write | No | Yes | No | 2 |
Only Write and Execute | No | Yes | Yes | 3 |
Only Read | Yes | No | No | 4 |
Only Read and Execute | Yes | No | Yes | 5 |
Only Read and Write | Yes | Yes | No | 6 |
Read Write and Execute | Yes | Yes | Yes | 7 |
Watch how to Give User Permission to Folder and Subfolders in Ubuntu
2 Scenarios to Give Folder and Subfolders Permissions in Ubuntu
In this article, I will demonstrate how to give user permission to folder and subfolders in Ubuntu distro of Linux. In the first case, I will give permission to folders and subfolders of my own from the terminal, then in the second case, I will give permission to the folder and subfolders owned by other users.
Case 01: Give Permission to Folder and Subfolders of Your Own in Ubuntu
Setting proper permission is essential in Ubuntu. You can easily set the appropriate permission from the terminal by using the chmod command. In this example, I will work with the following directory.Here, I will give writing permission to all the other users along with the owner and members of the group for the Project folder and subfolders inside the Project folder. To achieve so, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Now, copy the following command into the terminal to see the current permission
ls -lR
- ls: This command lists all the contents of the current directory.
- -lR: This option lists all the contents of the current directory and subdirectory inside this current directory with size, permission information, owner information, group information, last modification time, etc.
➌ Then, press ENTER.The above image shows that the Project folder and the Task_1, Task_2, and Task_3 subdirectories under the Project directory do not allow the other user to write these subdirectories.
➍ Now, type the following command into the command prompt to change the permission
chmod o+w -R Project
- chmod: This command changes the permission settings of the folder.
- o+w: This option sets the writing permission for other users.
- -R: This option sets the given permission of all the subfolders including the folder recursively.
- Project: This is the main folder that contains all other subfolders and I want to set writing permission for all other users.
➎ Then, press the ENTER button.
➏ Now, copy the following command into the terminal to see the current permission
ls -lR
- ls: This command lists all the contents of the current directory.
- -lR: This option lists all the contents of the current directory and subdirectory inside this current directory with size, permission information, owner information, group information, last modification time, etc.
➐ Then, press the ENTER button.
The above image shows that I have given writing permission for all other users for the Project folder and all subfolders(Task_1, Task_2, and Task_3) under the Project folder.
- How to Give Permission to User in Linux? [4 Methods]
- 2 Ways to Change Folder Permissions from Root to User in Linux
- How to Change File Permissions to 777 in Ubuntu?
- 2 Ways to Change Folder Permissions Recursively in Linux
Case 02: Change Permission of Folder and Subfolders of Other Users in Ubuntu
You can also change the permission of folders and subfolders of another user. For this, you have to use the sudo command and specify the absolute path. In this example, I will work with the following directory.Here, I will change the permission of the Class_VI folder and the subfolders inside the Class_VI folder owned by another user named other_user.
Now, to achieve so follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Now, type the following command in the command prompt
sudo chmod 777 -R /home/other_user/Desktop/Class_VI
- sudo: Grants root permission.
- chmod: This command changes the permission settings of the folder.
- 777: This option sets the reading, writing, and executing permission for the owner, group, and other users.
- -R: This option sets the given permission of all the subfolders including the folder recursively.
- /home/other_user/Desktop/Class_VI: This is the absolute path of the main folder that contains all other subfolders and I want to set writing permission for all other users.
➌ Then, press the ENTER button.
➍ Now, copy the following command in the terminal
sudo ls -lR /home/other_user/Desktop
- sudo: Grants the root permission
- ls: It prints the contents of the current directory.
- -lR: This option lists all the contents of the current directory and subdirectory inside this current directory with size, permission information, owner information, group information, last modification time, etc.
- /home/other_user/Desktop/Class_VI: This is the absolute path of the main folder that contains all other subfolders that I want to set writing permission for all other users.
➎ Then, press the ENTER button.The above image shows that the user named susmit has changed the permission of the Class_VI folder and subfolders inside the Class_VI folder owned by another user named other_user.
Complementary Information
Besides, knowing about creating multiple users in Linux, you will find the below information helpful.
Give User Permission to Root Folder in Ubuntu
Generally, only the owner of the root folder can read, write and execute the folder. Here, I will give the reading writing, and executing permission of the root folder to the group and all the other users. However, while changing permission always be very careful.Now, to do so, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Then, type the following command in the terminal
sudo chmod 777 root
- sudo: Grants root permission.
- chmod: This command changes the permission settings of the folder.
- 777: This option sets the reading, writing, and executing permission for the owner, group, and other users.
- root: I will give the reading writing, and executing permission of the root folder to the group and all the other users.
➌ Now, press the ENTER button.
➍ Then, copy the following command in the terminal and press the ENTER button.
ls -l
- ls: This command lists all the contents of the current directory.
- -lR: This option lists all the contents of the current directory and subdirectory inside this current directory with size, permission information, owner information, group information, last modification time, etc.
Conclusion
In this article, I have shown you the full process of how to give user permission to folder and subfolders in Ubuntu. By going through this article, you will be productive enough to change the permission of the folder and subfolder whenever necessary.
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 with 6 Examples
- How to Change Directories and Files Recursively with “chmod”
- Change Permissions on Mounted Drive in Linux
- How to Change Folder Permissions in Linux? [2 Methods]