访问控制列表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 22:06
下一篇 2016-08-07 22:06

相关推荐

  • shell脚本2

    使用read命令来接受输入 使用read来把输入值分配给一个或多个shell变量 read后面跟变量,回车输入内容,就可以把输入的内容赋给变量 -p指定要显示的提示 -s 静默输入,一般用于密码 输入的内容不显示 -n N 指定输入的字符长度N 当输入的内容达到了5个字符会直接结束输入 -d‘字符’ 输入结束符 把!作为了结束符,在输入内容时,当输入!会直接…

    2017-08-11
  • 脚本练习

    脚本练习: 1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 #!/bin/bash #功能:编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,…

    Linux干货 2016-08-12
  • 如何正确安装一个源码包

        下周就要考试了,心情挺忐忑不安的,前几天做了25期的考试题,感觉每个题都是老师上课讲过的,但是自己做却想不起来了。这应该就像学习数学一样,需要大量练习,做的多了自然就会了。     这周我们学习了如何使用yum,还学习了磁盘管理。针对如何安装源码包,以httpd包为例我们…

    2017-08-19
  • bash脚本之练习

    1、编写服务脚本/root/bin/testsrv.sh,完成如下要求  (1) 脚本可接受参数:start, stop, restart, status  (2) 如果参数非此四者之一,提示使用格式后报错退出 (3) 如是start:则创建/var/lock/subsys/SCRIPTNAME, 并显示“启动成功” 考虑:如果事先已经启…

    Linux干货 2016-08-24
  • 自制简易linux系统

    一、环境准备 1.笔记本电脑 2.vmware12软件 3.CentOS 6虚拟机 4.大于5G空间的物理磁盘分区 二、分区并挂载文件系统 1.添加磁盘 在vmware中选中CentOS 6系统并右击鼠标选择设置,添加–>硬盘–>SCSI(推荐)–>创建新虚拟磁盘–>大小改为5G–>完成 2.分区并…

    Linux干货 2016-09-20
  • CentOS 6上的防火墙策略的保存

    两种iptables的策略保存的方法

    2018-02-27