facl 文件訪問控制 setfacl、getfacl

    當一個用戶需要讀寫一個文件時,其文件的屬組和屬主都沒有相關的權限,如果給other讀寫權限的話,此時風險會比較大,這樣一來所有用戶都會有讀寫權限了。


普通用戶無法安全地將某個文件授權給其它用戶訪問

facl: 附加原有權限模型之上另一層權限控制機制,保存至文件擴展屬性信息中;

(a)查看文件的facl

    getfacl FILE ...


(b)、設定及取消文件的facl

  setfacl {-x|-m} 權限 FILE ...

常先選項:
        -m: 設定權限
            -m u:UserName:Perms  \\ 設置用戶的facl
            -m g:GroupName:Perms   \\ 設置給的facl
            -m m::Perms    \\ 設定mask值
        -x: 取消權限
            -x u:UserName
            -x g:GroupName
            -x m:

        -R: 遞歸


示例:

1、獲取文件的facl

[tom@zibbix tmp]$ getfacl test
# file: test   \\ 文件名
# owner: tom   \\ 屬主
# group: tom   \\ 屬組
user::rw-   \\ 屬主權限
group::rw-  \\ 屬組權限
other::r--  \\ 其它用戶權限


2、設置用戶user2對test文件有讀寫的權限

[tom@zibbix tmp]$ setfacl -m u:user2:rw- test
[tom@zibbix tmp]$ getfacl test
# file: test
# owner: tom
# group: tom
user::rw-
user:user2:rw-
group::rw-
mask::rw-  \\ 該mask值需要與user權限相對應才能生效,作爲權限的掩碼使用
other::r--

文件設置facl權限後,其權限位會增加一個+號

$ ls -l test
-rw-rw-r--+ 1 tom tom 0 Mar 18 17:28 test


2、取消test文件的facl權限

[tom@zibbix tmp]$ setfacl -x u:user2 test
[tom@zibbix tmp]$ getfacl test
# file: test
# owner: tom
# group: tom
user::rw-
group::rw-
mask::rw-
other::r--









發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章