访问控制列表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

相关推荐

  • Http协议中的各种长度限制总结

    HTTP1.0的格式 request(HTTP请求消息)结构:一个请求行.部分消息头,以及实体内容,其中的一些消息内容都是可选择的.消息头和实体内容之间要用空行分开. GET /index.html HTTP/1.1 //请求头,下面都是消息头.Accept: */*Accept-Languang:en-usConnection:keep-aliveHost…

    Linux干货 2015-04-04
  • 马哥教育网络班25期-第4周作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 ~]# cp -r /etc/skel/ /home/tuser1 ~]# cd /home/tuser1 tuser1]# ll -a 总用量…

    Linux干货 2016-12-26
  • 内核与内核模块

    内核与内核模块 先来看一下,内核与内核模块放在哪?这里以centos6为例 内核: /boot/vmlinuz或/boot/vmlinuz-version 内核解压所需要RAMDisk: /boot/initrc(/boot/initrc-version) 内核模块:/lib/modules/version/kernel或/lib/modules/uname…

    2017-09-04
  • 数组知识与编译安装

    数组知识与编译安装 一数组知识 1、定义数组    声明数组: declare -a ARRAY_NAME declare -A ARRAY_NAME:  关联数组 数组元素的赋值: (1)  一次只赋值一个元素; ARRAY_NAME[INDEX]=VALUE weekdays[0]="Sunday&quo…

    Linux干货 2016-09-19
  • RHCE系列之备份工具—-镜像备份Rsync

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1431426     我一哥们最近在搞备份,需要用到rsync。因此,鄙人就简单总结了下rsync,也就有了这篇博文,希望对51…

    Linux干货 2016-08-15
  • day5总结笔记

    本文内容: 索引节点 硬链接与软链接 重定向 用户组 useradd命令 索引节点: 索引节点包含了一个表,包含了有关文件的元数据,包含:     文件类型,权限,UID,GID 链接数(指向这个文件名路径名称个数)      该文件的大小和不同的时间戳。&n…

    系统运维 2016-08-08