ACL可以對某個文件設置該文件具體的某些用戶的權限,意思就是通過ACL可以對一個文件權限做擴展,可以不同的用戶對某個文件有不同的權限。
語法:
getfacl <文件名>
獲取文件的訪問控制信息
setfacl設置文件的acl
-m 修改文件的acl
-x 取消對文件的設置
setfacl –m u:用戶名:權限 文件名
setfacl –m g:組 名:權限 文件名
setfacl –x 用戶名文件名
setfacl –x g:組名文件名
[root@beryl ~]# touch file
[root@beryl ~]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
group::r--
other::r--
現在我們把、natasha用戶加上一個RWX的權限:setfacl -m u:natasha:rwx file
[root@beryl ~]# setfacl -m u:natasha:rwx file
[root@beryl ~]# ll file
-rw-rwxr--+ 1 root root 0 Apr 16 09:08 file
[root@beryl ~]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
user:natasha:rwx
group::r--
mask::rwx
other::r--
和設置ACL前有哪些區別?
用ll看,權限后面有個+就可能是設置了文件權限,所以沒必要沒個文件都用gefacl 去看
在查看acl的內容時候,我們看見多了行,natasha 用戶有了rwx的權限
然后我們用相似的命令把natasha組也加進去.給他RW的權限:setfacl -m g:natasha:rw file
[root@beryl ~]# setfacl -m g:natasha:rw file
[root@beryl ~]# ll file
-rw-rwxr--+ 1 root root 0 Apr 16 09:08 file
[root@beryl ~]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
user:natasha:rwx
group::r--
group:natasha:rw-
mask::rwx
other::r--
現在我們取消redhat用戶的權限:setfacl -x natasha file
[root@beryl ~]# setfacl -x natasha file
[root@beryl ~]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
group::r--
group:natasha:rw-
mask::rw-
other::r--
我們發現user:natasha:rwx這一行已經沒有了
[root@beryl ~]# setfacl -x g:redhat file
[root@beryl ~]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
group::r--
group:natasha:rw-
mask::rw-
other::r--
現在group:natasha:rw-這一行也沒有了
注意,撤消ACL操作:
對用戶直接加用戶名字就可以了
對組,在前面加g:組名
現在我們也取消redhat組的權限:setfacl -x g:natasha file