
我有兩個用戶,user1 和 user2,它們都是 groupA 的成員。 user2 在其主目錄中有一個名為folderA 的資料夾。如果他們希望允許 groupA 的所有成員具有讀寫執行權限,他們會怎麼做?
如果folderA 包含許多檔案和其他資料夾也需要具有讀寫執行權限怎麼辦?
網路上有關團體的資訊有點“參差不齊”,所以我在這裡提出我的問題,希望有人發布一個明確的答案,也可以幫助其他人。
謝謝!
答案1
資料夾A首先需要成為A組- 資料夾的擁有者或 root 可以執行此操作
chgrp groupA ./folderA
然後A組需要該資料夾的 rwx 權限
chmod g+rwx ./folderA
chgrp
如果需要,和命令中有一些選項chmod
可以遞歸到目錄中。
答案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