访问控制列表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.178linux.com/30122

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

相关推荐

  • week5

    1、显示当前系统上root、fedora或user1用户的默认shell; useradd fedora useradd user1 egrep "^(root|fedora|user1)" /etc/passwd | cut -d: -f1,7 2、找出/e…

    Linux干货 2016-11-24
  • LVS 之 初识LVS

    LVS 之 初识LVS LVS 之 初识LVS 0x00 概述 0x01 LVS拓扑结构图: lvs集群类型中的术语 : 0x02 lvs-type lvs-nat lvs-dr lvs-tun lvs-fullnat : 0x03 调度算法(scheduler) 0x00 概述 LVS : Linux Virtual Server lvs 工作在 IOS …

    2017-05-11
  • 第五周 练习

    1、显示当前系统上root、fedora或user1用户的默认shell; 1.  egrep "^(root|user1|fedora)" /etc/passwd|cut –d: –f7   2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:h…

    Linux干货 2016-11-28
  • PXE

    BootStraping 系统提供 PXE 简介 PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file…

    Linux干货 2016-11-05
  • linux程序包管理

    Linux程序包管理        API:Application Program Interface        ABI:Application Binary Interface           Unix-like, &n…

    Linux干货 2016-12-30
  • 计算机的组成及其功能

    计算机的组成及其功能 计算机由五部分组成 运算器 实现算术运算和逻辑运算(和控制器组成CPU) 控制器 控制总线的使用权限,完成寻址和控制对内存当中的访问权限是做读访问还是写访问 存储器 内存,RAM(Random Access Memory) 输入(Input) 下指令,提供数据 输出(Output) 输出数据加工的结果

    2018-02-22