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
- Having sudo/root privileges is necessary to change folder permissions.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
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
- ls: Lists content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of the “myfolder” folder.
❸ Then insert the command below to change permission from root to user:
sudo chown –R walid:walid ~/myfolder
- 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.
ls -ld ~/myfolder
- ls: Lists content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
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
- ls: Lists content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
❸ Then use the following command to change folder permissions from root to user:
sudo chgrp -R walid ~/myfolder
- 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.
ls -ld ~/myfolder
- ls: Lists content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
- How to Give Permission to User in Linux? [4 Methods]
- Change Folder Permissions in Linux? [2 Methods]
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 |
|
|
Using the chgrp command |
|
|
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 Change File Permissions to 777 in Ubuntu?
- 2 Ways to Change Folder Permissions Recursively in Linux
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
- ls: Lists content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
❸ Then execute the command below to give the user write permission:
chmod u+w ~/myfolder
- chmod: Changes permissions of a file or directory.
- u+w: Adding write permission to the User.
- ~/myfolder: Path of the “myfolder” directory.
ls -ld ~/myfolder
- ls: Lists the content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
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
- ls: Lists content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
❸ Then copy the command below to give the user full permission:
chmod u+rwx ~/myfolder
- 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.
ls -ld ~/myfolder
- ls: Lists content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
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
- ls: Lists content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
❸ Then insert the command below to give full permission to all:
chmod 777 ~/myfolder
- chmod: Changes permissions of a file or directory.
- 777: Read, write and execute permissions to all.
- ~/myfolder: Path of the “myfolder” directory.
ls -ld ~/myfolder
- ls: Lists the content of a directory.
- -l: Shows detailed information.
- -d: Shows information only of the given directory.
- ~/myfolder: Path of “myfolder” folder.
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
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
- 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