2 Cases to Give User Permission to Folder and Subfolders in Ubuntu

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.

Process Flow Chart to Give User Permission to Folders and SubfoldersProcess flow chart of giving user permission.

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS

Types of Permission in Linux

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-

EXPLANATION
  • 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 Cases 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 permit 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:Project folder tree. 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:

  1. First, open the Ubuntu terminal.
  2. Now, copy the following command into the terminal to see the current permission:
    ls -lR
    EXPLANATION
    • 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.
  3. Then, press ENTER.Showing the initial permission state of Project folder and subfolders inside it.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.

  4. Now, type the following command into the command prompt to change the permission:
    chmod o+w -R Project
    EXPLANATION
    • 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.
  5. Then, press the ENTER button.
  6. Now, copy the following command into the terminal to see the current permission:
    ls -lR
    EXPLANATION
    • 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.
  7. Then, press the ENTER button.

    Giving other user to write for Project folder and subfolders inside it, then showing changed permission state.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.



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, use the sudo command and specify the absolute path. In this example, I will work with the following directory:Tree of Class_VI folder and subfolders inside it. 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.Showing current working directory and initial permission state of Class_VI folder and subfolders inside it. Now, to achieve so follow the below procedures:

  1. At first, open the Ubuntu terminal.
  2. Now, type the following command in the command prompt:
    sudo chmod 777 -R /home/other_user/Desktop/Class_VI
    EXPLANATION
    • 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.
  3. Then, press the ENTER button.
  4. Now, copy the following command in the terminal:
    sudo ls -lR /home/other_user/Desktop
    EXPLANATION
    • 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.
  5. Then, press the ENTER button.Giving permission to read write and execute to all kind of user for Class_VI folder and subfolders inside it.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.

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.Showing current permission state of root folder.Now, to do so, follow the below procedures:

  1. At first, open the Ubuntu terminal.
  2. Then, type the following command in the terminal:
    sudo chmod 777 root
    EXPLANATION
    • 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.
  3. Now, press the ENTER button.
  4. Then, copy the following command in the terminal and press the ENTER button:
    ls -l
    EXPLANATION
    • 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.
    Changing permission of the root folder then showing changed permission state of root folder.The above image shows that after giving permission, the group members and other users now have the reading, writing, and executing permission of the root folder.

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

How to give full permission to folders and subfolders in Ubuntu?

You can do this task easily from the terminal using the chmod command. For example to give read permission to the group for the sample_file type “chmod g+r sample_file” and then press the ENTER button.

What is chmod 755?

Here, chmod changes the permission. 7 is the signal for the owner group to read, write and execute. 5 is the signal for the group members and other users to read and execute.

How do I give permission to read and write a folder in Ubuntu?

To give permission to read and write a folder in Ubuntu, you have to type the “chmod 660 [folder/file name]”  command in the command prompt and then press ENTER.

What kind of permission allows users to add files and subfolders?

Writing any content means deleting or modifying the content. So Write permission allows users to add files and subfolders.

How do I give file permission to the user?

To give file permission to a user you have to type the “chmod u+rwx [file_name]” command and then press ENTER.

What are the 2 ways that you can assign permissions to files and folders?

To give file permission to a user you have to type the “chmod u+rwx [file/folder_name]” or “chmod 777 [file/folder_name]” command and then press ENTER.

What is permission in Linux?

Permission in Linux is the access granted to users, groups, and others regarding files and directories. It specifies who can read, write, or even execute a file. Permissions are represented by 3 sets of characters and displayed as “r” for read, “w” for write, and “x” for execute permission.

What are the 3 types of permissions?

Three types of permission are read, write and execute. Read permission allows viewing the contents of a file or folder. Write permission allows to deletion or modify the contents of a file or folder. Execute permission allows to execution of a script file. In the case of a directory, execute permission means accessing contents or subdirectories within that directory.

How to change the folder and subfolder ownership in Linux?

To change the folder and subfolder ownership, use the chown command with the -R flag followed by the new owner’s username and specifying the directory path to change ownership recursively. For instance, sudo chown -R new_owner /path/to/folder changes the ownership of folder and its subfolders to new_owner.

How do I set special permissions for files and folders in Linux?

You can set special permission with the “chgrp” command to change the group, the “chown” command to change the group, and the “chmod” command to change the permission.

Related Articles

4.4/5 - (14 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Susmit Das Gupta

Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio

Leave a Comment