訪問控制列表ACL

 ACL是Access Control List的縮寫,主要的目的是提供傳統的owner、group、others的read、write、execute權限之外的具體權限設置。ACL可以針對單一用戶、單一文件、單一目錄來進行r、w、x的權限設置,對于需要特殊權限的使用狀況非常有幫助。使用getfacl和setfacl來設置查看acl的權限。ACL權限給了x,文件也不會繼承x權限。ACL上的mask只是一種限制權限的機制影響除所有者和other的之外的人和組的最大權限。mask需要與用戶的權限進行邏輯與運算后,才能變成有限的權限(Effective Permission),用戶或組的設置必須存在于mask權限設定范圍內才會生效。它也不會給文件x權限。

 

setfacl 設置acl屬性

語法

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

常用選項

-m  #設置后續的acl參數給文件使用,不可與-x合用
-M  #用文件或標準輸入來讀取acl的規則
-x  #刪除后續的acl參數,不可與-m合用
-X  #用文件或標準輸入來讀取acl的規則
-b  #刪除所有的acl設置參數
-k  #刪除默認的acl參數
-R  #遞歸設置acl

例如

[root@localhost testdir]# ls #列出文件
sun
[root@localhost testdir]# cat sun  #查看文件,其他只有r權限
sssaaaaaaaaaaaaaa
[root@localhost testdir]# setfacl -m u:tom:rw sun #設置acl權限
[root@localhost testdir]# getfacl sun #查看acl權限
# file: sun #文件名  "#"表示默認代表默認屬性
# owner: root #屬主
# group: root#屬組
user::rw- #文件所有者的權限
user:tom:rw- #自己設置的用戶權限
group::r--#用戶組的默認權限
mask::rw- #文件默認權限 
other::r-- #其他人擁有的權限
[root@localhost testdir]# ll 
total 4
-rw-rw-r--+ 1 root root 42 Aug  6 18:39 sun #設置acl后面會有個"+"號
[root@localhost testdir]# su tom #切換其他用戶
[tom@localhost testdir]$ echo "newfile i am very tired" >>sun #寫入數據。(按理不用改有次權限) 
[tom@localhost testdir]$ cat sun #由于設置了acl,所有有了rw權限。
sssaaaaaaaaaaaaaa
newfile i am very tired

mask就是一個界限,只能在它指定的范圍內的權限才可以。

[root@localhost testdir]# setfacl -m mask:r sun #設置mask默認為r
[root@localhost testdir]# getfacl sun #查看acl表
# file: sun
# owner: root
# group: root
user::rw-
user:tom:rw-#effective:r-- #有效值
group::r--
mask::r--
other::r--
[root@localhost testdir]# getfacl -R file > acl.txt #備份訪問控制列表到acl.txt文件中
[root@localhost testdir]# ll 
total 12
-rw-r--r--  1 root root 115 Aug  6 19:03 acl.txt
-rw-rw-r--+ 1 root root   5 Aug  6 17:55 file
-rw-r--r--  1 root root  45 Aug  6 17:44 file1
[root@localhost testdir]# cat acl.txt  #備份的acl條目
# file: file
# owner: root
# group: root
user::rw-
group::r--
group:Cloud:rwx#effective:rw-
mask::rw-
other::r--

[root@localhost testdir]# setfacl -b file #清空acl
[root@localhost testdir]# ll
total 12
-rw-r--r-- 1 root root 115 Aug  6 19:03 acl.txt
-rw-r--r-- 1 root root   5 Aug  6 17:55 file
-rw-r--r-- 1 root root  45 Aug  6 17:44 file1
[root@localhost testdir]# setfacl -R --set-file=acl.txt file #恢復acl
[root@localhost testdir]# ll
total 12
-rw-r--r--  1 root root 115 Aug  6 19:03 acl.txt
-rw-rw-r--+ 1 root root   5 Aug  6 17:55 file
-rw-r--r--  1 root root  45 Aug  6

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

(0)
ladsdmladsdm
上一篇 2016-08-07 22:06
下一篇 2016-08-07 22:06

相關推薦

  • 第十一周作業

    1、詳細描述一次加密通訊的過程,結合圖示最佳。   發送者:     1)使用單向加密算法提取要發送文件的特征碼;     2)使用自己的私鑰加密特征碼并附加在數據后面;     3)生成用于對稱加密的臨時密碼;     4)用此臨時密鑰加密數據和已經使用私鑰加密后的特…

    2017-05-08
  • LAMP的分布式實現——安裝wordpress、phpMyAdmin

    題目:分別用三臺centos 7主機分別部署 httpd, php-fpm, mariadb 第一臺 10.1.43.101 –>httpd 第二臺 10.1.43.102 –>php-fpm    分別在2臺虛擬主機上部署wordpress和phpmyadmin 第三臺 10.1.43.103 &#8…

    Linux干貨 2016-10-12
  • linux網絡屬性管理

    Linux網絡屬性配置 計算機網絡:TCP/IP:協議棧(使用)ISO,OSI:協議棧(學習) MAC:Media Access Control48bits:ICANN:24bits, 2^24地址塊:2^24 網橋(bridge):MAC地址表靜態指定:動態學習:根據原地址學習; 交換機(switch):多端口網橋; IP(Internet protoco…

    Linux干貨 2017-10-14
  • zabbix

    一、zabbix簡介 Zabbix是一個基于WEB界面的分布式開源監控系統,主要有2部分構成,Zabbix server于Zabbix agent,同時也支持Zabbix proxy。 現在,我們已經將Zabbix大量的應用到了線上環境。在日常的監控中,深切的體驗到了Zabbix的高效快捷和優秀的擴展能力。 Zabbix的底層采集程序是用C語言編寫的Serv…

    Linux干貨 2016-01-05
  • 第三周作業

    1. 列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次則顯示一次即可。 who | cut -d' ' -f1 | sort -u 2. 取出最后登錄當前系統的用戶的相關信息 grep  "$(who …

    Linux干貨 2016-12-19
  • 2016年8月11號學習博客

    shell腳本編程 shell腳本是包含一些命令或聲明,并符合一定格式的文本文件 shell腳本的用途有: 自動化常用命令 執行系統管理和故障排除 創建簡單的應用程序 處理文本或文件 命令查詢過程:別名–>內部變量–>hash–>$PATH ~]#bash -n 檢測腳本語法錯誤 ~]#bash -x 順…

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