ACL - 所有新建立的檔案自動使用相同的 ACL

ACL - 所有新建立的檔案自動使用相同的 ACL

我想為例如設定 ACL。 /tmp/test 資料夾如下:

/tmp/test 擁有者是使用者“gaspar”,群組“testgroup”的成員。
使用者「testuser」也是群組「testgroup」的成員,我只想向該使用者+擁有者(使用者「gaspar」)授予 rwx 權限。
另外,我需要自動為 /tmp/test 中所有新建立的檔案/目錄設定相同的 acl。

當我像這樣設定facl時:

setfacl -Rdm u:testuser:rwx,g:testgroup:-,o::- /tmp/test/

getfacl -p /tmp/test/授予權限:

# file: /tmp/test/
# owner: gaspar
# group: testgroup
user::rwx
group::---
other::---
default:user::rwx
default:user:testuser:rwx
default:group::---
default:group:testgroup:---
default:mask::rwx
default:other::---

然後使用者「testuser」沒有 /tmp/test 資料夾的權限。您能否建議問題出在哪裡,我該修正什麼?

當我像這樣設定 acl 時(沒有「d」選項),使用者「testuser」擁有他應該擁有的權限,但顯然新建立的檔案/目錄沒有相同的 acl:

setfacl -Rm u:testuser:rwx,g:testgroup:-,o::- /tmp/test/

getfacl -p /tmp/test/

# file: /tmp/test/
# owner: gaspar
# group: testgroup
user::rwx
user:testuser:rwx
group::---
group:testgroup:---
mask::rwx
other::---

任何建議表示讚賞!

答案1

在您的系統上,重新啟動後檔案就會/tmp消失,對嗎?也許這不是一個永久解決方案的好位置。在目錄上設定ACL 並將ACL 套用到目錄中的所有新檔案系統物件時,請記住設定兩個遮罩:(1) 目錄本身的遮罩和(2) 預設遮罩(對於所有新檔案系統對象) )。

setfacl -m u::rwx,g::r-x,o::--- /tmp/test
setfacl -d -m u::rwx,g::r-x,o::--- /tmp/test

上面的-m開關是 的掩碼/tmp/test,並且-d開關使該掩碼成為同一目錄中所有新檔案系統物件的預設遮罩。它相當於 0750。

使用者、群組和其他遮罩的工作方式相同:g:groupname:---或組合使用:u:username:---,g:groupname:---,o::---。不指定使用者名稱或群組名稱會將遮罩套用至目前使用者/群組所有權。

請注意,並非所有軟體都支援 ACL。例如,並非所有 SFTP/SCP 用戶端都知道它們。

答案2

這是應該的。

man acl關於預設 ACL 有以下說法:

存取控制清單類型

每個物件都可以被視為具有與其關聯的 ACL,該 ACL 控制對該物件的任意存取;該ACL稱為訪問ACL。此外,目錄可能有關聯的 ACL管理在該目錄中建立的物件的初始存取 ACL;該 ACL 被稱為預設ACL。

(強調我的)

您使用 ACL 指定的是,只有擁有者對該目錄具有 rwx 權限。目錄上的預設 ACL 指定以下內容:

  • 其中建立的所有檔案的 ACL 將設定為與父目錄的預設 ACL 相同。
  • 其中建立的所有目錄的預設 ACL 將設定為與父目錄的預設 ACL 相同

如果您變更父目錄的權限或新增啟用存取的群組/使用者 ACL,則其中的任何檔案都將按預期運作。

答案3

您需要了解什麼是「user::rwx 和default:user::rwx」繼承 acl 的預設部分。
有關更多信息,您需要閱讀“man setfacl”,也許這個文檔會幫助您:
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxb200/aclinhe.htm

相關內容