CentOS下ACL權限控制詳解

ACL權限控制
設置ACL權限:setfacl
查看ACL權限:getfacl
ACL權限控制主要目的是提供傳統(tǒng)的owner,group,other的read,wirte,execute權限之外的具體權限設置,可以針對單一用戶或組來設置特定的權限
比如:某一目錄權限為
drwx------ 2 root root 4096 03-10 13:51./acldir
用戶user對此目錄無任何權限因此無法進入此目錄,ACL可單獨為用戶user設置這個目錄的權限,使其可以操作這個目錄
ACL啟動
要使用ACL必須要有文件系統(tǒng)支持才行,目前絕大多數(shù)的文件系統(tǒng)都會支持,EXT3文件系統(tǒng)默認啟動ACL的
查看文件系統(tǒng)是否支持ACL
[root@localhost tmp]#
dumpe2fs -h /dev/sda2 dumpe2fs 1.39 (29-May-2006)
……
sparse_super large_file
Default mount options: user_xattr acl
加載ACL功能
如果UNIX LIKE支持ACL但是文件系統(tǒng)并不是默認加載此功能,可自己進行添加
[root@localhost tmp]# mount -o remount,acl /
[root@localhost tmp]# mount
/dev/sda2 on / type ext3 (rw,acl)
同樣也可以修改磁盤掛在配置文件設置默認開機加載
[root@localhost tmp]# vi /etc/fstab
LABEL=/ / ext3 defaults,acl 1 1
查看ACL權限
語法:getfacl filename
設置ACL權限
語法:setfacl [-bkRd] [-m|-x acl 參數(shù)] 目標文件名
選項與參數(shù):
-m:設置后續(xù)的acl參數(shù),不可與-x一起使用
-x: 刪除后續(xù)的acl參數(shù),不可與-m一起使用
-b:刪除所有的acl參數(shù)
-k:刪除默認的acl參數(shù)
-R:遞歸設置acl參數(shù)
-d:設置默認acl參數(shù),只對目錄有效
針對特殊用戶
設置格式:u:用戶賬號列表:權限
權限:rwx的組合形式
如用戶列表為空,代表設置當前文件所有者權限
舉例:
[root@localhost tmp]# mkdir -m 700 ./acldir; ll -d ./acldir
drwx------ 2 root root 4096 03-10 13:51 ./acldir
[root@localhost tmp]# su tkf
[tkf@localhost tmp]$ cd ./acldir/
bash: cd: ./acldir/: 權限不夠 =>用戶無X權限
[tkf@localhost tmp]$ exit
exit
[root@localhost tmp]# setfacl -m u:tkf:x ./acldir/
=>針對用戶tkf設置acldir目錄的權限為x
[root@localhost tmp]# ll -d ./acldir/
drwx--x---+ 2 root root 4096 03-10 13:51 ./acldir/
=>通過ACL添加權限在權限末尾會增加多個一個“+”同時文件原本權限也發(fā)生變化。
=>可通過getfacl查看原始目錄權限
[root@localhost tmp]# getfacl ./acldir/
# file: acldir
# owner: root
# group: root
user::rwx
user:tkf:--x =>記錄tkf用戶針對此目錄有acl權限
group::---
mask::--x
other::---
=>這里需要特殊說明,只是tkf這個用戶具有X權限,其他用戶還是無權限的
[root@localhost tmp]# su tkf
[tkf@localhost tmp]$ cd ./acldir/
[tkf@localhost acldir]$
=>用戶tkf可以具有x權限可以進入目錄
針對特定用戶組
設置格式:g:用戶組列表:權限
權限:rwx的組合形式
如用戶組列表為空,代表設置當前文件所屬用戶組權限
舉例:
[root@localhost tmp]# setfa
setfacl setfattr
[root@localhost tmp]# setfacl -m g:users:rx ./acldir/
[root@localhost tmp]# getfacl ./acldir/
# file: acldir
# owner: root
# group: root
user::rwx
user:tkf:--x
group::--- => 其他用戶組(非acl設置)的權限
group:users:r-x => 記錄users用戶組針對此目錄有acl權限
mask::r-x
other::---
針對有效權限設置
有效權限(mask)就是acl權限設置的極限值,也就是你所設置的acl權限一定是mask的一個子集,如果超出mask范圍會將超出的權限去掉
設置格式:m:權限
權限:rwx的組合形式
舉例:
[root@localhost tmp]# setfacl -m m:x ./acldir/
[root@localhost tmp]# getfacl ./acldir/
# file: acldir
# owner: root
# group: root
user::rwx
user:tkf:--x
group::r-x #effective:--x
group:users:r-x #effective:--x
mask::--x
other::---
針對默認權限設置
我們前面都是針對一個目錄為一個用戶(組)設置特定權限,但是如果這個目錄下在新創(chuàng)建的文件是不具有這些針對這個用戶的特定權限的。為了解決這個問題,就需要設置默認acl權限,使這個目錄下新創(chuàng)建的文件有和目錄相同的ACL特定權限
設置格式:d:[u|g]:用戶(組)列表:權限
舉例
[root@localhost tmp]# mkdir -m 711 ./defdir
[root@localhost tmp]# setfacl -m u:tkf:rxw ./defdir
[root@localhost tmp]# ll -d ./defdir/
drwxrwx--x+ 2 root root 4096 03-10 15:23 ./defdir/
=>目錄權限具有acl特定權限(后面+)
[root@localhost tmp]# touch ./defdir/a.file;ll ./defdir/
-rw-r--r-- 1 root root 0 03-10 15:25 a.file
=>新創(chuàng)建的文件不具有acl特定權限(后面無+)
[root@localhost tmp]# setfacl -m d:u:tkf:rxw ./defdir
=>設置默認權限
[root@localhost tmp]
# getfacl ./defdir/
# file: defdir
# owner: root
# group: root
user::rwx
user:tkf:rwx
group::--x
mask::rwx
other::--x
default:user::rwx
default:user:tkf:rwx
default:group::--x
default:mask::rwx
default:other::--x
[root@localhost tmp]# touch ./defdir/b.file;ll ./defdir/
-rw-r--r-- 1 root root 0 03-10 15:25 a.file
-rw-rw----+ 1 root root 0 03-10 15:26 b.file
=>新創(chuàng)建文件默認帶有acl特定權限
[root@localhost tmp]
# getfacl ./defdir/b.file
# file: defdir/b.file
# owner: root
# group: root
user::rw- user:tkf:rwx #effective:rw-
group::--x #effective:---
mask::rw-
other::---
=>這快我有個疑問,為什么mask值是rw,我猜測和文件最大權限有關,
=>對于文件來時默認最大權限是666即UMASK為0000.那個對于可執(zhí)行文件來說
=>沒有X,難道還需要使用chmod設置? 疑問??!
相關文章
如何解決centos下root運行Elasticsearch異常
有些朋友在centos下root運行Elasticsearch時發(fā)現(xiàn)異常;不知道該如何解決?下面小編就給大家?guī)斫鉀Qcentos下root運行Elasticsearch異常的方法!有需要的朋友可以過來看看2016-11-28centos:/tmp不能運行導致的安裝編譯錯誤問題解決方法
這篇文章主要介紹了centos:/tmp不能運行導致的安裝編譯錯誤問題解決方法,需要的朋友可以參考下2016-08-25在CentOS下使用Munin來監(jiān)控服務器運行的方法
這篇文章主要介紹了在CentOS下使用Munin來監(jiān)控服務器運行的方法,Munin支持Nginx和Apache等服務器軟件,需要的朋友可以參考下2015-06-26在CentOS或Fedora上運行Docker容器的方法與步驟
最近,炙手可熱Docker已儼然成為將應用程序部署到云環(huán)境的一種關鍵技術,在本教程中,我將介紹如何在CentOS或Fedora上創(chuàng)建和管理Docker容器,需要的朋友可以參考一下2014-10-15- 今天小編為大家?guī)淼氖荂entOS進程和計劃任務管理的詳解;希望會對大家有幫助;有需要的朋友可以過來看看2016-12-13
Centos下如何為進程綁定CPU?Centos下為進程綁定CPU的方法
一些朋友還不知道Centos下如何為進程綁定CPU?下面小編就為大家?guī)鞢entos下為進程綁定CPU的方法;一起去看看吧2016-12-13- 今天,小編為大家分享的是Centos進程狀態(tài)詳解;希望對大家的學習會有幫助;有需要的朋友可以過來看看2016-12-07
CentOS系統(tǒng)上搭建Git版本控制服務器的教程
這篇文章主要介紹了CentOS系統(tǒng)上搭建Git版本控制服務器的教程,包括創(chuàng)建SSH key以及打開RSA認證等遠程連接的相關配置方法講解,需要的朋友可以參考下2016-04-26在CentOS系統(tǒng)中安裝SVN版本控制軟件的教程
這篇文章主要介紹了在CentOS系統(tǒng)中安裝SVN版本控制軟件的教程,盡管近年來被Git搶盡風頭,但SVN簡便的操作方式依然受到很多開發(fā)者的青睞,需要的朋友可以參考下2016-03-31CentOS系統(tǒng)安裝使用版本控制系統(tǒng)Subversion的方法
subversion是一個版本控制系統(tǒng),在CentOS系統(tǒng)中要如何使用subversion,下面為大家介紹下CentOS安裝使用subversion的方法,感興趣的朋友可以看看2015-03-31