問題描述
我有兩個用戶,user1 和 user2,他們都是 groupA 的成員。 user2 在其主目錄中有一個名為 folderA 的文件夾。如果他們希望為 groupA 的所有成員授予 read-write-execute 權限,他們會怎麽做?
如果 folderA 包含許多文件和其他文件夾也需要具有 read-write-execute 權限怎麽辦?
關於群組的信息在網絡上很少見 ‘spotty’,所以我把我的問題放在這裏,希望有人發布一個明確的答案,這也可能對其他人有所幫助。
謝謝!
最佳辦法
FolderA 首先需要成為 groupA 的一部分 – 文件夾的所有者或根可以執行此操作
chgrp groupA ./folderA
然後 groupA 將需要文件夾的 rwx 權限
chmod g+rwx ./folderA
如果需要,chgrp
和 chmod
命令中有選項可以遞歸到目錄中。
次佳辦法
我自己在這方麵的經驗在這裏。在 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