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.

Key Takeaways

  • Changing folder permissions using the chown command.
  • Changing folder permissions using the chgrp command.
  • Viewing permissions of a folder.
  • Providing writing permissions to a user.
  • Giving full permissions to a user.
  • Providing full permissions to all.

Requirements

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTSProcess flow chart for "change folder permissions from root to user in Linux"

Watch how to Change Folder Permissions from Root to User in Linux

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. Now I will show you how to change the owner of a folder from “root” to a user who is “walid” in this case.

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

Method 01: Using the chown Command to Change Permissions from Root to User

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

Steps to Follow >

❶ At first, launch a Terminal in Ubuntu.

❷ (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”.

❸ 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❹ (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 02: Using the chgrp Command to Change Permissions from Root to User

The chgrp command in Linux is used to change the Group ownership of a file or directory. In this method, I will use the chgrp command to 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.

Steps to Follow >

❶ Firstly, open a Terminal in Ubuntu.

❷ (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”.

❸ 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 “myfolder” folder.
  • ~/myfolder: Path of the “myfolder” folder.
Showing how to change folder permissions from root to user in Linux using the chgrp command.❹ (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, the User hasn’t changed. However, the Group is “walid” instead of “root”.

Comparative Analysis of Methods

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.

Complementary Information

Here I have provided some additional information related to the main topic of this article.

What are Ownership and Permission in Linux?

In general, there are three types of file permissions that 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 owner:

  • 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 Give 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. You can follow the steps shown here to provide write permission for a user.

Steps to Follow >

❶ At first launch a Terminal in Ubuntu.

❷ (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.

❸ 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"❹ (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

Sometimes it may require giving full permission to a user of a file or directory. Follow the steps below to do that –

Steps to Follow >

❶ Press CTRL+ALT+T to launch an Ubuntu Terminal.

❷ (Optional) Now write 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.
Previous permissionsNone has any permission here. In the following step, I will provide the user with full access to the folder.

❸ Then copy the command below to give the user full permission:

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.
Providing read, write and execute permission to the user for "change folder permissions from root to user in Linux"❹ (Optional) At the end, use the command below to view new 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.
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

In 777, the three digits represent 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. Now to give full permission to all, follow the steps below.

Steps to Follow >

❶ Firstly, open a Ubuntu Terminal.

❷ (Optional) Now use 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.
Previous permissionsHere the dashes (“-”) indicate that none has any permission whatsoever. However, I will provide all full permission now.

❸ Then insert the command below to give full permission to all:

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.
Providing full access to all❹ (Optional) At last, use the command below to view the new permissions of the folder:
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 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, 644 represents 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 Other –

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 option “-f” of the chmod command. For instance, I want to give everyone access of the file name “myfile.txt”, I will force change permissions by the following command-

chmod -f 777 myfile.txt

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

How do I give read and write permission to non root user?
You need sudo privileges to give read and write permission to non-root user. Then you need to use the following command

sudo chmd u+rw myfile.txt

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

How to check root access in Linux?
Firsty, you can run any command that requires root privileges (for instance – sudo passwd), check you are able to 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. 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

Rate this post
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