允许组对目录进行读写访问


40

我有两个用户user1和user2,它们都是groupA的成员。user2在其主目录中有一个名为folderA的文件夹。如果他们希望允许groupA的所有成员具有读写执行权限,他们将如何做?

如果folderA包含许多文件和其他文件夹,这些文件也需要具有读写执行权限,该怎么办?

有关组的信息在网络上有点“杂乱无章”,因此,我在此提出问题,希望有人发布明确的答案,也可能对其他人有所帮助。

谢谢!

Answers:


56

FolderA首先需要成为groupA的一部分-文件夹的所有者或根用户可以执行此操作

chgrp groupA ./folderA

然后,groupA将需要该文件夹的rwx权限

chmod g+rwx ./folderA

chgrp和chmod命令中有一些选项可以根据需要递归到目录中。


注意:您还应确保也可以访问中间目录(+ x可能就足够了)。
jfs

我最初尝试过chown :groupname ./folder,但是没有用-改变了组,但没有提供任何有效的权限
user230910

2

我在这方面的经验。原始方法。在Ubuntu 18.04上测试。

允许在系统文件夹中写入

授予/etc/nginx/文件夹写权限。

# Check 'webmasters' group doen't exist
cat /etc/group | grep webmasters
# Create 'webmasters' group
sudo addgroup webmasters
# Add users to 'webmasters' group
sudo usermod -a -G webmasters username
sudo usermod -a -G webmasters vozman
sudo usermod -a -G webmasters romanroskach

# Group assignment changes won't take effect
# until the users log out and back in.

# Create directory
sudo mkdir /etc/nginx/
# Check directory permissions
ls -al /etc | grep nginx
drwxr-xr-x   2 root root     4096 Dec  5 18:30 nginx

# Change group owner of the directory
sudo chgrp -R webmasters /etc/nginx/
# Check that the group owner is changed
ls -al /etc | grep nginx
drwxr-xr-x   2 root webmasters   4096 Dec  5 18:30 nginx

# Give write permission to the group
sudo chmod -R g+w /etc/nginx/
# Check
ls -al /etc | grep nginx
drwxrwxr-x   2 root webmasters   4096 Dec  5 18:30 nginx

# Try to create file
sudo -u username touch /etc/nginx/test.txt  # should work
sudo -u username touch /etc/test.txt  # Permission denied

授予/etc/systemd/system/文件夹写权限。

# List ACLs
getfacl /etc/systemd/system

getfacl: Removing leading '/' from absolute path names
# file: etc/systemd/system
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

# Add 'webmasters' group to an ACL
sudo setfacl -m g:webmasters:rwx /etc/systemd/system

# Check
getfacl /etc/systemd/system

getfacl: Removing leading '/' from absolute path names
# file: etc/systemd/system
# owner: root
# group: root
user::rwx
group::r-x
group:webmasters:rwx
mask::rwx
other::r-x

sudo -u username touch /etc/systemd/system/test.txt  # should work
sudo -u username touch /etc/systemd/test.txt  # Permission denied
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.