In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to give users read and write access to a specified directory on Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "how to give users read and write access to a specified directory on Linux".
There are two ways to achieve this: * use ACL (access control list), and the second is to create user groups to manage file permissions, which are described below.
To complete this tutorial, we will use the following settings.
Operating system: CentOS 7
Test directory: / shares/project1/reports
Test user: tecmint
File system type: ext4
Make sure that all commands are executed using the root user, or use the sudo command to enjoy the same permissions.
Let's get started! Next, use the mkdir command to create a directory called reports.
# mkdir-p / shares/project1/reports
Use ACL to give users read and write permissions to directories
Important: if you plan to use this method, you need to make sure that your Linux file system types (such as ext3 and ext4, NTFS, BTRFS) support ACL.
1. First, check the current file system type on your system and see if the kernel supports ACL according to the following command:
# df-T | awk'{print $1 acl 2 grep NF}'| grep "^ / dev" # grep-I acl / boot/config*
As you can see from the screenshot below, the file system type is ext4, and from the CONFIG_EXT4_FS_POSIX_ACL=y option, you can see that the kernel supports POSIX ACL.
Check the file system type and ACL support for the kernel.
2. Next, check whether the ACL option is used when mounting the file system (partition).
# tune2fs-l / dev/sda1 | grep acl
Check to see if the partition supports ACL
From the output above, you can see that ACL is already supported in the default mount project. If you find that the result is not what you want, you can turn on ACL support for the specified partition (/ dev/sda3 in this case) with the following command.
# mount-o remount,acl / # tune2fs-o acl / dev/sda3
3. Now is the time to assign read and write permissions to the directory reports to the user named tecmint. Follow the command below.
# getfacl / shares/project1/reports # Check the default ACL settings for the directory # setfacl-m user:tecmint:rw / shares/project1/reports # Give rw access to user tecmint # getfacl / shares/project1/reports # Check new ACL settings for the directory
Assign read and write permissions to the specified directory through ACL
In the screenshot above, you can find that the user tecmint has been successfully granted read and write permissions to the / shares/project1/reports directory by the second line of the getfacl command that outputs the result.
If you want more information about the ACL list. You can view our other guides below.
How to use access Control lists (ACL) to set disk quotas for users / groups
How to mount a network share using access control lists (ACL)
Now let's look at how to use the second method to give read and write permissions to directories.
Use user groups to give users read and write access to a specified directory
1. If the user already has a default user group (usually the group name is the same as the user name), you can simply change the user group of the folder.
# chgrp tecmint / shares/project1/reports
In addition, we can also create a new user group for multiple users (those who need to be given read and write permissions to the specified directory) in the following ways. In this way, a shared directory is created.
# groupadd projects
2. Next, add user tecmint to the projects group:
# usermod-aG projects tecmint # add user to projects# groups tecmint # check users groups
3. Change the user group of the directory to be more projects:
# chgrp projects / shares/project1/reports
4. Now, set read and write permissions for group members.
# chmod-R 0760 / shares/projects/reports # ls-l / shares/projects/ # check new permissions Thank you for your reading. The above is the content of "how to give users read and write access to a specified directory on Linux". After the study of this article, I believe you have a deeper understanding of how to give users read and write access to a specified directory on Linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.