2 Ways to Change Folder Permissions from Root to User in Linux

There could be different reasons for changing folder permissions from root to a particular user. For instance, an administrator may need to provide access to a user of a folder. In addition, it is necessary for collaboration. In this article, I will show you how to change folder permissions from root to user in Linux.

Process flow chart to change folder permissions from root to user:Process flow chart for "change folder permissions from root to user in Linux"

[Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS]

2 Methods to Change Folder Permissions from Root to User in Linux

A folder has three types of owners: User, Group, and Other; where the root user is a special type of User who enjoys administrative privileges. In addition, an owner has three permissions: read(r), write(w) and execute(w). Here is more on ownership and permission.

To change folder permissions from root to user in Linux, you can either use the chown command or the chgrp command. Using the chown command, you can change permissions for both the owner and group but with the chgrp command, you can only change permission for the group. Now I will show you how to change the owner of a folder from root to a user who is “walid” in this case.

However, for using chown or chgrp command to change folder permissions from root to user, you must have sudo/root privileges.

You can read our Comparison of Methods to distinguish between these two methods and best pick one for your need.

Method 1: Using the “chown” Command to Change Permissions from Root to User

The sole purpose of the chown command is to change ownership and eventually permissions of a file or directory. For instance, my Ubuntu has a folder named “myfolder”. Here, I will change the owner of “myfolder” from root to user, “walid”.

To change permissions of a folder from root to user, you have to use the chown command. Here is an example:

  1. At first, launch a Terminal in Ubuntu.
  2. (Optional) Copy the following command to view the current owner:
    ls -ld ~/myfolder
    EXPLANATION
    • ls: Lists content of a directory.
    • -l: Shows detailed information.
    • -d: Shows information only of the given directory.
    • ~/myfolder: Path of the myfolder folder.
    Showing current ownerAs you can see, both the current User and Group are root. Now I will change them to the user walid.
  3. Then insert the command below to change permission from root to user:
    sudo chown –R walid:walid ~/myfolder
    EXPLANATION
    • sudo: Grants root privileges.
    • chown: Changes ownership.
    • -R: Recursive Change; changes will be applied to all files and subdirectories within “myfolder”.
    • walid:walid: New User and Group.
    • ~/myfolder: Path of the myfolder folder.
    Showing how to change folder permissions from root to user in Linux using the chown command
  4. (Optional) Finally, to check the new owner, write the following command:
    ls -ld ~/myfolder
    EXPLANATION
    • ls: Lists content of a directory.
    • -l: Shows detailed information.
    • -d: Shows information only of the given directory.
    • ~/myfolder: Path of myfolder folder.
    Printing current ownerNow both the User and the Group are “walid” instead of “root”.

Method 2: Using “chgrp” Command to Change Group Permissions from Root to User

The chgrp command in Linux is used to change the Group ownership of a file or directory. Here, I will change the Group ownership from “root” to “walid”. However, unlike the chown command, it isn’t possible to change the User using the chgrp command.

To change the group permissions from root to user, use the chgrp command. Here is how:

  1. Firstly, open a Terminal in Ubuntu.
  2. (Optional) Insert the following command to view the current owner:
    ls -ld ~/myfolder
    EXPLANATION
    • ls: Lists content of a directory.
    • -l: Shows detailed information.
    • -d: Shows information only of the given directory.
    • ~/myfolder: Path of myfolder folder.
    Previous ownerHere both the User and Group are “root”. I will change the Group from “root” to user “walid”.
  3. Then use the following command to change folder permissions from root to user:
    sudo chgrp -R walid ~/myfolder
    EXPLANATION
    • sudo: Grants root privileges.
    • chgrp: Changes the Group ownership of a file or directory.
    • -R: Recursive Change; changes will be applied to all files and subdirectories within “myfolder”.
    • walid: New Group owner of the myfolder folder.
    • ~/myfolder: Path of the myfolder folder.
    Showing how to change folder permissions from root to user in Linux using the chgrp command.
  4. (Optional) Finally, to check the new owner, write the following command:
    ls -ld ~/myfolder
    EXPLANATION
    • ls: Lists content of a directory.
    • -l: Shows detailed information.
    • -d: Shows information only of the given directory.
    • ~/myfolder: Path of myfolder folder.
    New ownerHere you can see that the User hasn’t changed. However, the Group is “walid” instead of “root”.


Comparison of Methods to Change Folder Permissions from Root to User

You can change folder permissions from root to user in Linux using the chown and chgrp commands. Here is a comparison between these two methods:

Methods Pros Cons
Using the chown command
  • Can change both the User and Group owner.
  • Can be combined with other commands.
  • Requires root privileges.
  • May cause issues if not careful.
Using the chgrp command
  • Useful if you want to grant a group access to a folder.
  • More efficient in changing Group ownership.
  • Requires root privileges.
  • Only changes Group owner.

If you aren’t sure which command to use, go with the chown command.

What are Ownership and Permission in Linux?

In general, three types of file permissions are set for three categories of owners in Linux. The permissions are represented by a 10-character string, with the first character representing the file type (– for normal files & d for directory). Check the following sections where I will explain in detail.

Ownership in Linux

Linux has the following three types of owners:

  • User: Represents the creator or main owner of the file. The owner has full control over the file and can modify its permissions.
  • Group: A collection of users who share a common set of permissions. When a file is created, it is assigned to a specific group & all users who are members of that group, are granted the same permissions on the file.
  • Other: Refers to all users who are not the owner of the file, also who do not belong to the group that the file belongs to. Other users are granted permissions separately from the owner and group.

Types of Permissions

A file or directory in Linux has the following three types of permissions:

  • Read (r): Allows a user to view the contents of a file or lists of a directory, but cannot modify them.
  • Write (w): Allows a user to modify the contents of a file or to create, delete, or rename files in a directory. For example, a user with only written permission on a file can modify its contents but can’t view or execute it.
  • Execute (x): Allows a user to run an executable file or change into a directory, but can not view or write onto it.


How to Set Write Permission to a Folder for a User in Linux

Giving write permission to a user of a folder allows him to create, modify, and delete files. To set write permission to a folder for a user, follow the below steps:

  1. First launch a Terminal in Ubuntu.
  2. (Optional) Now insert the following command to view current permissions:
    ls -ld ~/myfolder
    EXPLANATION
    • ls: Lists content of a directory.
    • -l: Shows detailed information.
    • -d: Shows information only of the given directory.
    • ~/myfolder: Path of myfolder folder.
    Printing current permissions As you can see, user “walid” has no permission whatsoever. Now I will give the user write permission.
  3. Then execute the command below to give the user write permission:
    chmod u+w ~/myfolder
    EXPLANATION
    • chmod: Changes permissions of a file or directory.
    • u+w: Adding write permission to the User.
    • ~/myfolder: Path of the myfolder directory.
    Providing writing permission to the user for "change folder permissions from root to user in Linux"
  4. (Optional) Finally, copy the following command to print new permissions:
    ls -ld ~/myfolder
    EXPLANATION
    • ls: Lists the content of a directory.
    • -l: Shows detailed information.
    • -d: Shows information only of the given directory.
    • ~/myfolder: Path of myfolder folder.
    New permissionsNow the user “walid” has write permission.

How to Give Full Permission to User in Ubuntu

To give full permission to a user, you need to use chmod u+rwx. Here is an example:

chmod u+rwx ~/myfolder
EXPLANATION
  • chmod: Changes permissions of a file or directory.
  • u+rwx: Adding read, write, and execute permissions to the User.
  • ~/myfolder: Path of the myfolder directory.

User with read, write and execute permissionsIn the above image, you can see that the user has full permission now.

How to Change Linux Permissions 777 Using the “chmod” Command

The 777 represents permissions for the three types of owners (User, Group, Other) in Linux. Moreover, number 7 means read (4), write (2) and execute (1) permissions. Thus, in short, 777 denotes full permissions for all.

To give full permission to all, use chmod 777 command. Here is how:

chmod 777 ~/myfolder
EXPLANATION
  • chmod: Changes permissions of a file or directory.
  • 777: Read, write and execute permissions to all.
  • ~/myfolder: Path of the myfolder directory.

New permissions where all have access to the "myfolder" folderIt is showing “rwxrwxrwx”, so everyone has full permission now.

Conclusion

In this article, I have focused on how to change the permissions of a folder from root to user in Linux. I have provided multiple methods for this particular task and their comparison as well so that you choose a suitable method for you. In the end, I have also added some complimentary information and questions that may arise. Hopefully, all of those were helpful.

People Also Ask

What does chmod 644 mean?

In chmod 644, the three digits represent the owner’s, group’s and other’s permissions respectively. In addition, number 6 denotes read and write permissions and number 4 denotes read permission only. Thus, in short, chmod 644 means changing the read and write permissions for the owner and read permission for everyone else.

How do I give permission to non root user in Linux?

To give permission to a non-root user in Linux, you can use the chmod command. For instance, the following command will give read, write and execute permissions to the User and only read permission to the Group and Others: chmod u+rwx,g+r,o+r myfile.txt.

How do I give admin rights to a normal user in Linux?

To give admin rights to a normal user in Linux, you can add the user to the sudo group. Use the following command:

sudo usermod -aG sudo USERNAME

How do I force change permissions in chmod?

To force change permissions, you need to use the option -f of the chmod command. For instance, if I want to give everyone access to the file name “myfile.txt”, I will force change permissions in chmod by the following command:

chmod -f 777 myfile.txt

Why use sudo instead of root?

Sudo is more secure as instead of logging in as root, a user can utilize the root privileges using it. Moreover, in Ubuntu, the root is locked by default. So, sudo is the only way to do some specific tasks.

How do I give read and write permission to non root user?

To give read and write permission to non-root user, you have to use the chmod command. Here is an example:

sudo chmod u+rw myfile.txt

However, you need sudo privileges to give read and write permission to non-root user.

How to change root user to superuser?

The root user is already a superuser. Therefore, the question is not accurate. However, to switch to root user or super user, you should use the following command: sudo su.

What is the root permission?

Root permission also known as root access is the highest level of administrative permissions. It is commonly referred to as the superuser account and has full access to the whole system.

How to check root access in Linux?

To check root access in Linux, first, you can run any command that requires root privileges (for instance – sudo passwd), and check whether you can run it properly. If the answer is “yes”, then you are a root user. Secondly, you can check the sudo group to view the users with root access by the following command: getent group sudo.

Does root override file permissions?

Yes, the root user can override file permissions. In general, a root user in Linux has access to any files, directories and resources. As a result, he can override file permissions.


Related Articles

5/5 - (4 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

Leave a Comment