文件基本權限-ACL

文件權限管理之: ACL設置基本權限(r、w、x)

UGO設置基本權限: 只能一個用戶,一個組和其他人
ACL 設置基本權限: r,w,x
//Access Control List 訪問控制列表

ACL基本用法

設置:
[root@localhost ~]# touch /home/test.txt
[root@localhost ~]# ll /home/test.txt
-rw-r--r-- 1 root root 0 10-26 13:59 /home/test.txt

[root@localhost ~]# getfacl /home/test.txt
[root@localhost ~]# setfacl -m u:alice:rw /home/test.txt //增加用戶alice權限
[root@localhost ~]# setfacl -m u:jack:- /home/test.txt //增加用戶jack權限
[root@localhost ~]# setfacl -m o::rw /home/test.txt

查看/刪除:
[root@localhost ~]# ll /home/test.txt
-rw-rw-r--+ 1 root root 0 10-26 13:59 /home/test.txt
[root@localhost ~]# getfacl /home/test.txt
[root@localhost ~]# setfacl -m g:hr:r /home/test.txt
[root@localhost ~]# setfacl -x g:hr /home/test.txt //刪除組hr的acl權限

[root@localhost ~]# setfacl -b /home/test.txt //刪除所有acl權限 

 ACL高級用法

mask:
用於臨時降低用戶或組(除屬主和其他人)的權限
建議:爲了方便管理文件權限,其他人的權限置爲空

示例:mask值影響用戶權限的舉例
[root@localhost ~]# touch /home/file1
[root@localhost ~]# setfacl -m u:gougou:rw /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::rw-
user:gougou:rw-
group::r--
mask::rw-
other::r--

[root@localhost ~]# setfacl -m m::r /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::rw-
user:gougou:rw- #effective:r--
group::r--
mask::r--
other::r--

[root@localhost ~]# su - gougou
[gougou@localhost ~]$ cat /home/file1
[gougou@localhost ~]$ vim /home/file1 

使用vim打開文件之後無法對文件進行修改

[root@localhost ~]# setfacl -m o::rwx /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::---
user:alice:rw-
group::---
mask::rw-
other::rwx
[root@localhost ~]# setfacl -m m::r /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::---
user:alice:rw- #effective:r-- 有效權限:r
group::---
mask::r--
other::rwx
[alice@localhost ~]$ cat /home/file1
333
[alice@localhost ~]$ vim /home/file1
使用vim打開文件之後無法對文件進行修改,因爲我們的mask值是r,不是空的,所以alice用戶不會繼承other的權限
[root@localhost ~]# setfacl -m m::- /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::---
user:alice:rw- #effective:---
group::---
mask::---
other::rwx

[root@localhost ~]# su - alice
[alice@localhost ~]$ cat /home/file1
333
ddd
[alice@localhost ~]$ vim /home/file1
這個時候使用vim打開文件的時候就可以對文件的內容進行修改了,因爲mask值爲空,所以alice會繼承other的身份


總結:
mask的值不爲空的時候,單獨設置用戶或者是組的acl權限就受自己的權限的影響,不包括user(屬主)和other(其他人),但是如果將mask的值設置爲空,單獨設置過acl權限的用戶會受other的權限的影響。

default: 繼承(默認)
要求: 希望alice能夠對/tmp/dir100以及以後在/tmp/dir100下新建的文件有讀、寫、執行權限

[root@localhost tmp]# mkdir dir100
[root@localhost tmp]# touch dir100/file1 dir100/file2

一: 賦予alice對/tmp/dir100以及目錄下以存在的文件和文件夾讀、寫、執行權限
[root@localhost ~]# setfacl -R -m u:alice:rwx /tmp/dir100
[root@localhost tmp]# getfacl dir100/file1
# file: dir100/file1
# owner: root
# group: root
user::rw-
user:alice:rwx
group::r--
mask::rwx
other::r--

[root@localhost tmp]# getfacl dir100/file2
# file: dir100/file2
# owner: root
# group: root
user::rw-
user:alice:rwx
group::r--
mask::rwx
other::r--

[root@localhost tmp]# touch dir100/file3
[root@localhost tmp]# getfacl dir100/file3
# file: dir100/file3
# owner: root
# group: root
user::rw-
group::r--
other::r--


二: 賦予alice對以後在/tmp/dir100下新建的文件有讀、寫、執行權限 (使alice的權限繼承)
[root@localhost ~]# setfacl -m d:u:alice:rwx /tmp/dir100
[root@localhost tmp]# getfacl dir100/
# file: dir100/
# owner: root
# group: root
user::rwx
user:alice:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:alice:rwx
default:group::r-x
default:mask::rwx
default:other::r-x

[root@localhost tmp]# touch dir100/file4
[root@localhost tmp]# getfacl dir100/file4
# file: dir100/file4
# owner: root
# group: root
user::rw-
user:alice:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--

注意:文件的x權限不能隨便給的,所以系統會自動的將文件的x權限減掉

[root@localhost tmp]# mkdir dir100/dir200
[root@localhost tmp]# getfacl dir100/dir200/
# file: dir100/dir200/
# owner: root
# group: root
user::rwx
user:alice:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:alice:rwx
default:group::r-x
default:mask::rwx
default:other::r-x

[root@localhost tmp]# mkdir dir100/dir200/dir300
[root@localhost tmp]# getfacl dir100/dir200/dir300
# file: dir100/dir200/dir300
# owner: root
# group: root
user::rwx
user:alice:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:alice:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
[root@localhost tmp]# touch dir100/dir200/dir300/file1
[root@localhost tmp]# getfacl dir100/dir200/dir300/file1
# file: dir100/dir200/dir300/file1
# owner: root
# group: root
user::rw-
user:alice:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--


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