訪問控制列表ACL使用說明

一、什么是ACL

ACL(Access Control List)可靈活地,更細粒度地定義訪問文件或目錄的權限。

二、為什么使用ACL

Linux上文件系統的文件系統權限管理的對象分為三類:owner,group,other。這種分類非常簡單,如果我希望有一個用戶擁有不同于這三類對象的權限,或者再定義一個用戶組的權限,傳統的權限管理就不能實現,而ACL可以很好的解決這個問題。

三、ACL條目

 一系列ACL條目構成了ACL。條目應包含標簽類型(tag type),可選擇的標簽修飾定語,以及權限設定。

其中標簽類型分為:

 1.acl_user_obj:  文件的屬主

 2.acl_user:     自定義用戶

 3.acl_group_obj:  文件的所屬組

 4.acl_group:    自定義用戶組

 5.acl_mask:    規定了acl_user,acl_group_obj,acl_group可被授予的最大權限

 6.acl_other:    不在acl里定義的其他用戶

[root@centos7 data]# getfacl f1
# file: f1
# owner: root
# group: mysql
user::rwx                #acl_user_obj
user:cutemsyu:rw-        #acl_user               
group::r-x               #acl_group_obj          #effective:r--
group:cutemsyu:rw-       #acl_group
group:fly:r--            #acl_group
mask::rw-                #acl_mask
other::---               #acl_other

 tag type 可簡寫,如u表示user,g表示group。

四、ACL設置和查看方法

 setfacl :設置    getfacl :查看

 格式:setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file …

     getfacl [-aceEsRLPtpndvh] file …

 1、直接設置模式:

 -m :修改權限

 -x :移除權限

 –set:設置權限,取代原來的acl權限設置,必需包含u,g,o的tag type

 例如,修改權限并查看

[root@centos7 testdir]# setfacl -m u:cutemsyu:r,g:cutemsyu:r example
[root@centos7 testdir]# getfacl example
# file: example
# owner: root
# group: root
user::rw-
user:cutemsyu:r--
group::r--
group:cutemsyu:r--
mask::r--
other::r--

 移除權限并查看

[root@centos7 testdir]# setfacl -x g:cutemsyu example
[root@centos7 testdir]# getfacl example 
# file: example
# owner: root
# group: root
user::rw-
user:cutemsyu:r--
group::r--
mask::r--
other::r--

 2、通過文件設置

 ACL支持讀取文件來設置權限

 -M:修改權限

 -X:移除權限

 這里我給出一個文本acl_file,

[root@centos7 testdir]# cat acl_file 
u:cutemsyu:rw         #一行只能寫一個條目
u:fly:rw
g:cutemsyu:r

 修改權限并查看

[root@centos7 testdir]# touch example2
[root@centos7 testdir]# setfacl -M acl_file example2
[root@centos7 testdir]# getfacl example2
# file: example2
# owner: root
# group: root
user::rw-
user:cutemsyu:rw-
user:fly:rw-
group::r--
group:cutemsyu:r--
mask::rw-
other::r--

 再創建一個文本用來移除權限

[root@centos7 testdir]# cat acl_file_remove 
u:cutemsyu
u:fly
g:cutemsyu

 移除權限并查看

[root@centos7 testdir]# setfacl -X acl_file_remove example2
[root@centos7 testdir]# getfacl example2
# file: example2
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--

 3、為目錄設置ACL

 為目錄設置ACL,設置方法相同,可用-R進行遞歸

 另外目錄的ACL可加默認權限,不作用于目錄本身,表示再此目錄下新建的文件或目錄繼承默認權限

 例如:

[root@centos7 testdir]# setfacl -m o::-,u:fly:rwx,d:u:fly:rwx test/   #d:表示默認權限
[root@centos7 testdir]# getfacl test/
# file: test/
# owner: root
# group: root
user::rwx
user:fly:rwx
group::r-x
mask::rwx
other::---
default:user::rwx                   #未定義的默認tag type會跟隨目錄相應權限
default:user:fly:rwx
default:group::r-x
default:mask::rwx
default:other::---

 在此目錄下新建目錄和文件,查看ACL

[root@centos7 test]# mkdir dir1;touch file1;
[root@centos7 test]# getfacl dir1 file1 
# file: dir1
# owner: root
# group: root
user::rwx
user:fly:rwx
group::r-x
mask::rwx
other::---
default:user::rwx
default:user:fly:rwx
default:group::r-x
default:mask::rwx
default:other::---

# file: file1
# owner: root
# group: root
user::rw-
user:fly:rwx			#effective:rw-
group::r-x			#effective:r--
mask::rw-           #文件mask不繼承x權限
other::---

 4、復制一個文件的ACL

 setfacl 支持管道輸入 –set-file=-

getfacl file1|setfacl --set-file=- example      #復制file1權限到example

 5、備份和恢復ACL

 mv和cp備份文件時都會保留ACL信息,cp指令需加-p選項

 但是tar等工具工具備份文件時不會保留ACL信息,這時需要我們備份ACL信息

getfacl -R /testdir/data  >acl.bak         #遞歸備份ACL信息
setfacl -R --set-file=acl.bak /testdir/data        #遞歸恢復ACL信息

 6、清除ACL

setfacl -k dir       #清除默認acl設置
setfacl -b file      #清除所有acl設置

五、ACL和文件權限位的關系

 設置ACL的文件或目錄,ls -l 查看權限位最后的 "."會變成"+"

drwxrwx---+ 2 root root 6 Aug  6 10:32 dir1

 owner位與ACL中acl_user_obj 對應

 group位與ACL中acl_mask對應

 other位與ACL中acl_other對應

六、ACL權限允許訪問邏輯

 當一個線程訪問一個被ACL保護的文件時,其獲權邏輯如下:

 1.當線程的有效用戶ID與文件owner相匹配時,如果owner擁有相應權限,則允許訪問,否則拒絕。

 2.當線程的有效用戶ID與acl_user相匹配時,如果mask和acl_user都具有相應權限則允許訪問,否則拒絕。

 3.當線程的有效組ID或者補充組ID與文件所屬組或任意acl_group相匹配時,

  (1)當ACL含有mask條目時

     如果mask和任何匹配的組擁有相應權限,則允許訪問,否則拒絕

  (2)當ACL不含有mask條目時

     如果文件所屬組擁有相應權限,則允許訪問,否則拒絕

 4.如果acl_other擁有相應權限,則允許訪問

 5.其他則拒絕

原創文章,作者:cutemsyu,如若轉載,請注明出處:http://www.www58058.com/29774

(0)
cutemsyucutemsyu
上一篇 2016-08-08 16:16
下一篇 2016-08-08 16:16

相關推薦

  • 網絡服務基礎理論

    最近學習了有關網絡管理的有關知識,所以給也在學習這些知識的童鞋分享一下我的一些經驗。 聽了這幾天課,總結了幾個前提。 有關網絡的通信均是基于數據傳輸的,且數據均是二進制格式的流式數據。 在網絡中需要把大包分成小包, 每傳一個包都需要有三個地址,由內向外為端口號、IP地址、MAC地址。端口號確定應用,IP確定網段,MAC確定廣播域中的某個網卡。 OSI模型 &…

    Linux干貨 2017-09-01
  • 馬哥教育網絡班21期+第一周課程練習

    1,描述計算機的組成及其功能。 2.按系列羅列linux的發行版,并描述不同發行版之間的練習與區別。 3.描述linux的哲學思想,并按照自己的理解對其進行解釋性描述。 1.       一切皆文件,計算機中所有的文件目錄,        包括計算機的硬件設備顯示為文件格式。 2…

    Linux干貨 2016-07-07
  • LVM基本原理及使用

    LVM簡介 LVM全稱Logical Volume Manager(邏輯卷管理),是將幾個物理分區(或硬盤)通過軟件組合成一塊看起來是獨立大硬盤(VG),然后對這塊大硬盤分割成可使用的邏輯卷(LV),最終能夠掛載使用,以達到對磁盤空間進行彈性管理的目的。 LVM的基本原理 基本術語 dm(device mapper):將一個或多個底層塊設備組織成一個邏輯設備…

    Linux干貨 2016-04-17
  • LVS小記

    19.LVS小記    LVS的類型:        nat:是一種基于IP的DNAT的,通過目標端口與目標地址利用特定的算法選取出響就的主機進行響應,通過RS(Real Server)的地址和端口進行轉發            特點:&n…

    2017-05-15
  • Yellow Dog! COMMAND && source

    linux程序包管理之yum        yum:之前命名為:yellow dog ,后來因為及其好用,很多發行版都以此為默認rpm程序前端管理工具,故此更名為:yellowdog update modifier,更牛的還有一個基于redhat的二次發行版也叫yellow dog 功能:…

    Linux干貨 2016-08-21
欧美性久久久久