ACL文件访问控制列表

一、ACL文件访问控制列表

前言

1️⃣:ACL—文件访问控制列表;

2️⃣:ACL可以针对单个用户,单个文件或目录来进行r、w、x的权限设定,特别适用于需要特殊权限的使用情况。

3️⃣:ACL就是可以设置特定用户或用户组对于一个文件/目录的操作权限,可以实现灵活的权限管理,除了文件的所有者,所属组和其它人,可以对更多的用户设置权限

4️⃣:ACL就是可以设置特定用户或者用户组对于一个文件/文件夹的操作权限

5️⃣:LINUX上的ACL访问控制列表,主要的目的是在提供传统的u(user)、g(group)、o(other)的r(read)、w(write)、x(execute)权限之外的局部权限设定

1、ACL管理命令

getfacl
setfacl

2、ACL形式

每个片段的形式都如:tag:name:perm
tag可以是下面形式的一种:
    user    表示这是一个用户的ACL条目
    group   表示这是一个用户组的ACL条目
    other   表示这是其它的ACL条目
    mask    表示这是一个掩码的ACL条目,最大的有效权限(权限阈值)
    
    name    可以是用户名或组名
    perm    是指该用户或组所具有的权限,它是由"rwx"组成的一个字符串

3、setfacl

setfacl
    使用 setfacl 设定文件访问控制列表
    语法  setfacl {-m|-x|-b|-d ...} filename  

选项
    -m, --modify=acl     设置ACL条目,不可与-x一起使用
    -x, --remove=acl     删除所设置的ACL条目,不可与-m一起使用
    -b, --remove-all     删除所有ACL条目(包括默认的ACL条目)
    -k, --remove-default 删除默认ACL条目
    -R, -- recursion     递归设置ACL条目,包括余下的子目录或子文件都将被设置ACL条目
    -d, --default        对目录设置默认的ACL条目,并且在改目录下创建的文件都将继承该目录的默认ACL条目(该选项只能对目录生效)
    
示例
    setfacl -m u:zyq:rwx test.sh
    user     简写为u,
    group    简写为g   
    other    简写为o

注意:使用 -m 对other设置facl的时候,只需指明对应的权限即可,无需指明特定的用户;其次,对其他用户无法使用-x选项,因为,其他用户不同于所属主和所属组,只需给特定的权限即可

4、getfacl

getfacl
    使用getfacl可以获取文件访问控制列表
    语法:getfacl filename

选项
    -a, --access 仅显示文件访问控制列表
    -d, --default 仅显示默认的访问控制列表
    -c, --omit-header 不显示注释表头
    
示例
    getfacl test.txt
    # file: test.txt         //文件名
    # owner: root            //文件拥有者
    # group: root            //文件拥有组
    user::rw-                //说明该文件的拥有者拥有读和写的权限
    group::rw-               //说明该文件的拥有组有读和写的权限
    mask::rw-                //说明mask的权限是读和写
    other::---               //说明其他人没有权限访问该文件

5、操作示例

//创建ACL条目
[root@localhost ~]# ll test 
-rw-r--r--. 1 root root 0 8月   5 15:33 test
[root@localhost ~]# setfacl -m u:zhangsan:rw test 
[root@localhost ~]# getfacl test 
# file: test
# owner: root
# group: root
user::rw-
user:zhangsan:rw-     //说明zhangsan用户对该文件拥有读和写的权限
group::r--
mask::rw-          //mask权限说明zhangsan用户对改文件的权限最大只能是读和写
other::r--

//删除ACL条目
[root@localhost ~]# setfacl -x u:zhangsan test 
[root@localhost ~]# getfacl test 
# file: test
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--

//给目录设置默认的ACL条目
[root@localhost ~]# mkdir dir
[root@localhost ~]# ll -d dir
drwxr-xr-x. 2 root root 6 8月   5 15:41 dir
[root@localhost ~]# setfacl -m d:u:zhangsan:rw dir
[root@localhost ~]# getfacl dir/
# file: dir/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:zhangsan:rw-
default:group::r-x
default:mask::rwx
default:other::r-x

//在dir目录下创建一个文件,看是否继承该目录的ACL条目
[root@localhost ~]# touch dir/file1
[root@localhost ~]# getfacl dir/file1 
# file: dir/file1
# owner: root
# group: root
user::rw-
user:zhangsan:rw-
group::r-x			#effective:r--
mask::rw-
other::r--

//删除dir目录的默认ACL条目
[root@localhost ~]# setfacl -k dir
[root@localhost ~]# getfacl test 
# file: test
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--
或者
[root@localhost ~]# setfacl -b dir/
[root@localhost ~]# getfacl dir/
# file: dir/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

 

posted @ 2020-08-05 15:26  阮小言  阅读(355)  评论(0编辑  收藏  举报