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

相关推荐

  • Redis学习手册(持久化)

    一、Redis提供了哪些持久化机制:     1). RDB持久化:     该机制是指在指定的时间间隔内将内存中的数据集快照写入磁盘。         2). AOF持久化:     该机制将以日志…

    Linux干货 2015-02-25
  • 文本处理工具以及grep

    文本处理工具以及grep 我们在使用Linux系统的时候需要查看、分析或者统计文件,这时候我们就需要使用到文本处理工具。 我们先来看下几个文本处理工具的使用: 文件内容:less和 cat 文件截取:head和tail 按列抽取:cut 按关键字抽取:grep 我们先来看看less和cat cat:查看文件命令     用法: &nbsp…

    Linux干货 2016-08-08
  • Linux基础知识之history命令详解

     该博文以CentOS6.8_x86_64系统为基础,Xshell 5远程连接CentOS系统,以root身份登录系统。 为什么要学习history命令?     history命令是Linux的一个内嵌的shell命令,history命令的使用有时会大大缩短我们输入命令的时间,达到节省命令快捷操作的要求。学…

    Linux干货 2016-07-27
  • socket阻塞与非阻塞,同步与异步、I/O模型

    1. 概念理解      在进行网络编程时,我们常常见到同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)四种调用方式:同步:      所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不返回。也就是必须一件一件事做,等前…

    Linux干货 2015-04-10
  • N25第一周作业-Linux初步认识

    一.描述计算机的组成及其功能。     计算机组成有两部份,一为硬件,二为软件OS         硬件:CPU,负责运算操作。          &…

    Linux干货 2016-12-06
  • 基于haproxy实现wordpress动静分离

    环境:centos 6.8 注:此处省略对于各服务器的IP配置。 一:图示讲解      用户访问vip,通过haproxy代理得到服务器的资源。此架构下基于keepalived对haproxy做负载均衡(此种两种软件装在同一台服务器),基于haproxy对Nginx和apache做负载均衡,Nginx和Apache使用共享存储…

    2017-05-18