ACL允许向文件分配细化的权限。除标准的文件所有者、组所有者、和其他文件权限之外,还可以指定用户或组,以及uid或guid确定的用户和组授予权限。

命令:

·setfacl 设置acl策略

·getfacl 查看acl策略

[root@server ~]# setfacl --help
setfacl 2.2. -- set file access control lists
Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ...
-m, --modify=acl modify the current ACL(s) of file(s) #设置文件或目录ACL规则
-M, --modify-file=file read ACL entries to modify from file #从文件读取ACL规则
-x, --remove=acl remove entries from the ACL(s) of file(s) #删除ACL规则
-X, --remove-file=file read ACL entries to remove from file #从文件读取ACL规则,并且进行删除
-b, --remove-all remove all extended ACL entries #删除所有扩展ACL规则,基本ACL规则保留
-k, --remove-default remove the default ACL #删除默认ACL规则,如果没有默认ACL规则,不提示
--set=acl set the ACL of file(s), replacing the current ACL #
--set-file=file read ACL entries to set from file
--mask do recalculate the effective rights mask #重新计算有效权限,即使ACL Mask被明确指定
-n, --no-mask don't recalculate the effective rights mask #不要重新计算有效权限
-d, --default operations apply to the default ACL #设置默认ACL规则,只是针对目录而言
-R, --recursive recurse into subdirectories #递归设置ACL规则
-L, --logical logical walk, follow symbolic links
-P, --physical physical walk, do not follow symbolic links
--restore=file restore ACLs (inverse of `getfacl -R')
--test test mode (ACLs are not modified)
-v, --version print version and exit
-h, --help this help text
[root@server ~]# mkdir /sharedata
[root@server ~]# cp /etc/passwd /sharedata/
[root@server ~]# useradd usera
[root@server ~]# useradd userb
[root@server ~]# useradd userc
[root@server ~]# echo 'userabc' |passwd --stdin usera
Changing password for user usera.
passwd: all authentication tokens updated successfully.
[root@server ~]# echo 'userabc' |passwd --stdin userb
Changing password for user userb.
passwd: all authentication tokens updated successfully.
[root@server ~]# echo 'userabc' |passwd --stdin userc
Changing password for user userc.
passwd: all authentication tokens updated successfully.
[root@server ~]# cd /sharedata/
[root@server sharedata]# ll
total
-rw-r--r-- root root Oct : passwd
[root@server sharedata]# setfacl -m u:usera:r passwd
[root@server sharedata]# setfacl -m u:userb:rw passwd
[root@server sharedata]# setfacl -m u:userc:rwx passwd
[root@server sharedata]# getfacl passwd
# file: passwd
# owner: root
# group: root
user::rw-
user:usera:r--
user:userb:rw-
user:userc:rwx
group::r--
mask::rwx
other::r--

如果想让ACL在目录下的数据都有继承功能,通常会对这个目录设置默认权限

文件所有者可以在单个文件或目录上设置ACL。新文件和子目录可以自动从父目录默认ACL中继承ACL设置。 与常规文件的访问规则类似,父目录层次结构需要至少设置其它执行权限,以便启用指定用户和指定组的访问权限。

[root@server ~]# mkdir /sharedata
[root@server sharedata]# setfacl -m d:u:usera:rwx /sharedata/
[root@server sharedata]# su - usera
Last login: Thu Oct :: CST on pts/
[usera@server ~]$ cd /sharedata/
[usera@server sharedata]$ touche usera
bash: touche: command not found...
Similar command is: 'touch'
[usera@server sharedata]$ touch usera
touch: cannot touch ‘usera’: Permission denied
[usera@server sharedata]$ exit
logout
[root@server sharedata]# mkdir -p /sharedata/pub
[root@server sharedata]# su - usera
Last login: Thu Oct :: CST on pts/
[usera@server ~]$ cd /sharedata/pub/
[usera@server pub]$ touch usera
[usera@server pub]$ cd ..
[usera@server sharedata]$ touch usera
touch: cannot touch ‘usera’: Permission denied

ACL掩码
掩码定义可授予指定用户组、组所有者和指定组的最大权限。不限制文件所有者或其它用户的权限
如果设置了mask,和mask比较,最终取得是二者中最小权限

[root@server /]# cd sharedata/
[root@server sharedata]# cp /etc/passwd .
[root@server sharedata]# setfacl -m u:usera:r passwd
[root@server sharedata]# setfacl -m u:userb:rw passwd
[root@server sharedata]# setfacl -m u:userc:rwx passwd
[root@server sharedata]# getfacl passwd
# file: passwd
# owner: root
# group: root
user::rw-
user:usera:r--
user:userb:rw-
user:userc:rwx
group::r--
mask::rwx
other::r-- [root@server sharedata]# setfacl -m m:r passwd
[root@server sharedata]# getfacl passwd
# file: passwd
# owner: root
# group: root
user::rw-
user:usera:r--
user:userb:rw- #effective:r--
user:userc:rwx #effective:r--
group::r--
mask::r--
other::r-- [root@server sharedata]# setfacl -m m:rwx passwd
[root@server sharedata]# getfacl passwd
# file: passwd
# owner: root
# group: root
user::rw-
user:usera:r--
user:userb:rw-
user:userc:rwx
group::r--
mask::rwx
other::r--

RHCE7 管理II-6ACL的使用的更多相关文章

  1. RHCE7 管理II-4计划将来的Linux任务

    (1) at 一次性的计划任务 语法: # at [参数] [时间] at> 执行的指令 退出at命令 ctrl+d [root@localhost ~]# at now at> mkdi ...

  2. RHCE7 管理I-12归档文件并在Linux系统间复制文件

    tar命令使用 默认tar只有归档的功能,没有压缩功能 tar [option...] [file]... -c,--create     创建 -x,--extract,--get   解压 -t, ...

  3. RHCE7 管理II-5管理进程的优先级

    进程的优先级值称为进程的nice值,共有40种不同的取值(用数字-20到19表示) nice值越大,表示进程的优先级越低. 进程的nice值,只允许root用户来设置负的nice:其他用户只允许设置正 ...

  4. RHCE7 管理II-2 通过grep使用正则表达式

    grep -i:忽略大小写 -n:表示行数 找出含有root的行 # grep root /etc/passwd root:x:::root:/root:/bin/bash ::operator:/r ...

  5. RHCE7 管理II-3使用VIM编辑器

    vim的不同版本: 1.vim-minial 提供vi和相关命令.在RHEL 7的最小安装中 2.vim-enhanced 提供vim命令.提供语法突出显示.文件类型插件和拼写检查等功能 3.vim- ...

  6. phper 要求

    做了这么多年php,今天看到一个07年的老文,才发现自己的水平太菜.转过来激励下自己 说句实话,写这个真够无聊的.本来看了某位大虾的类似文章,腹诽了几句也就算了.但是昨天晚上有个客户拿着这篇文章问我: ...

  7. PHPer的等级划分

    PHPer的等级划分 前一段时间刚刚完成PHP的培训,然后想知道自己目前的水平(或者说等级),并且应该在哪些方面进行提高,所以在网上查了一下相关介绍.其中有一篇介绍讲的挺清楚的,至少目前的我还是很认同 ...

  8. java打包jar,war,ear包的作用、区别

    java的打包jar,war,ear包的作用,区别,打包方式. a) 作用与区别      i.    jar: 通常是开发时要引用通用(JAVA)类,打成包便于存放管理      ii.   war ...

  9. Spring_Aop的xml和注解的使用

    动态代理:    目的:在不改变源代码的情况下,对方法进行增强!        动态代理又分为两种:    1.第一个就是基于接口的动态代理,他是由jdk提供的    2.基于子类的动态代理:cgli ...

随机推荐

  1. Informatica 常用组件Lookup之十 创建查找转换

    在 Mapping Designer 中选择"转换-创建".选择查找转换.输入转换名称.查找转换的命名惯例是 LKP_TransformationName.单击"确定&q ...

  2. hdu 4445 Crazy Tank

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  3. ASP.NET MVC中使用jQuery时的浏览器缓存问题

    介绍 尽管jQuery在浏览器ajax调用的时候对缓存提供了很好的支持,还是有必要了解一下如何高效地使用http协议. 首先要做的事情是在服务器端支持HTTP GET,定义不同的URL输出不同的数据( ...

  4. Android数据解析-JSON解析

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,基于JavaScript(Standard ECMA-262 3rd Edition - December ...

  5. Maximal Rectangle leetcode java

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones ...

  6. jquery 返回顶端组件

    自己写了一个基于jquery的返回页面顶端的组件. (function($) { var g; $.backtop = function(options) { extend($.backtop.con ...

  7. 巧妙使用div+css模拟表格对角线

    首先声明: 这只是探讨一种CSS模拟表格对角线的用法,实际在工作中可能觉得这样做有点小题大作,这不是本主题讨论的重点.如果对此深以为然的朋友,请一笑过之... 有时在插入文档时,要用到表格对角线,常见 ...

  8. c#写扩展方法

    学习MVC时,学会了写扩展方法,用起来很方便. 01 using System; 02 using System.Collections.Generic; 03 using System.Linq; ...

  9. 如何通过js关闭微信浏览器页面

    WeixinJSBridge.call('closeWindow'); jssdk wx.closeWindow(); WeixinJSBridge对象还提供了哪些功能: WeixinJSBridge ...

  10. Spark Streaming事务处理彻底掌握

    本篇文章主要从二个方面展开: 一.Exactly Once 二.输出不重复 事务: 银行转帐为例,A用户转账给B用户,B用户可能收到多笔钱,如何保证事务的一致性,也就是说事务输出,能够输出且只会输出一 ...