ACL理论概述

9位的属主/属组/其他人访问控制系统已经得到证明是强大的,足以满足大多数管理方面的需求。

事实上,在所有非UNIX操作系统上都采用了一种实质上更为复杂的方式来管理对于文件的访问:访问控制列表(access control list),简称ACL。ACL不限制长度,可以包含用于多个用户或者用户组的权限规定。更先进的系统能让系统管理员指定部分权限的集合或者否定方式的权限。

因为在POSIX规范中增加了ACL,所以许多UNIX的变体也开始支持一种相当标准的ACL机制,这种机制和传统的UNIX 9位权限模式平行地发挥左右。

Linux的ACL主要是对标准的9位权限模型直接进行扩展。ACL可以按照用户和用户组的任意组合独立地设置rwx权限位。

ACL的主要命令

getfacl 命令可以显示一个文件当前的ACL

$ getfacl --help
getfacl 2.2. -- get file access control lists
Usage: getfacl [-aceEsRLPtpndvh] file ...
-a, --access display the file access control list only
-d, --default display the default access control list only
-c, --omit-header do not display the comment header
-e, --all-effective print all effective rights
-E, --no-effective print no effective rights
-s, --skip-base skip files that only have the base entries
-R, --recursive recurse into subdirectories
-L, --logical logical walk, follow symbolic links
-P, --physical physical walk, do not follow symbolic links
-t, --tabular use tabular output format
-n, --numeric print numeric user/group identifiers
-p, --absolute-names don't strip leading '/' in pathnames
-v, --version print version and exit
-h, --help this help text

setfacl 命令可以修改或者设置文件当前的ACL

$ 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)
-M, --modify-file=file read ACL entries to modify from file
-x, --remove=acl remove entries from the ACL(s) of file(s)
-X, --remove-file=file read ACL entries to remove from file
-b, --remove-all remove all extended ACL entries
-k, --remove-default remove the default 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
-n, --no-mask don't recalculate the effective rights mask
-d, --default operations apply to the default ACL
-R, --recursive recurse into subdirectories
-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

ACL实例

1. ACL随着chmod命令对权限模式位的修改而自动更新

$ touch example
$ ls -l example
-rw-rw-r-- eric eric Dec : example
$ getfacl example
# file: example
# owner: eric
# group: eric
user::rw-
group::rw-
other::r--
$ chmod example
$ getfacl --omit-header example
user::rw-
group::r--
other::---

2. Mask规定了ACL能够给单个组和用户访问权限的上限。扩充上一个例子里的ACL,让它包括对某个特定用户和组的ACL,setfacl会自动提供一个合适的mask

$ ls -l example
-rw-r----- eric eric Dec : example
$ setfacl -m user::r,user:squid:rw,group:squid:rw example
$ ls -l example
-r--rw----+ eric eric Dec : example
$ getfacl --omit-header example
user::r--
user:squid:rw-
group::r--
group:squid:rw-
mask::rw-
other::---

如上所示,setfacl命令产生了一个mask,让ACL中赋予的所有权限都发生了作用。在尝试访问文件的时候,要把有效UID同该文件属主的UID进行对比。如果他们一样,那么ACL中user::项权限就决定了能否访问。否则,匹配某个特定用户的ACL项,那么ACL项连同ACL的mask就一起决定了能否访问。如果没有特定于某个用户,那么文件系统会尝试找有效的组ACL项;如果还没有匹配项,那么在用other::这个ACL项。

3. 如果在一个有ACL的文件上,用chmod来控制组的访问权限,那么修改只对mask有影响。

$ getfacl --omit-header example
user::r--
user:squid:rw-
group::r--
group:squid:rw-
mask::rw-
other::---
$ ls -l example
-r--rw----+ eric eric Dec : example
$ chmod example
$ ls -l example
-rwxrwx---+ eric eric Dec : example
$ getfacl --omit-header example
user::rwx
user:squid:rw-
group::r--
group:squid:rw-
mask::rwx
other::---

这里的ls输出有点误导性。尽管表面上看给组权限,但是没有人因为是组成员而有权执行该文件,为了让组有这样的权限,必须用setfacl编辑ACL本上。

Linux下的ACL的更多相关文章

  1. linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制)

    linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制) 发表于2012//07由feng linux 本身的ugo rwx的权限,对于精确的权限控制很是力不从心的,ac ...

  2. Shell初学(八)linux下的ACL

    [1]ACL的作用 简单直接解释一下ACL的作用,即把权限的个别化额外添加. 可以解决如下问题~~比如: [1.1]基于用户: 我有10个用户a1-a10,我有一个文件夹/tmp/test,我想给a1 ...

  3. 构建LINUX下的入侵检测系统——LIDS 系统管理命令--vlock

    构建LINUX下的入侵检测系统——LIDS   系统管理命令--vlock http://blog.chinaunix.net/uid-306663-id-2440200.html LIDS官方网站: ...

  4. Linux下Nagios的安装与配置

    一.本文说明 本文是在参考:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html   David_Tang文章以及网上的一些资料完 ...

  5. linux下恢复误删除的文件方法(ext2及ext3)

     linux下恢复误删除的文件方法(ext2及ext3) 2009-12-19 15:23:47 分类: LINUX 如果是ext2文件系统的,直接用debugfs是可以恢复出来的,但对于ext3,d ...

  6. Linux下部署Symfony2对app/cache和app/logs目录的权限设置

    在linux下部署完Symfony2,可能在访问的时候会报app/logs或者app/cache目录没有写权限的错误.在linux下,如果我们在命令行登陆的用户和web应用服务器(apache.ngi ...

  7. Linux UGO和ACL权限管理

    自主访问控制(Discretionary Access Control, DAC)是指对象(比如程序.文件.进程)的拥有者可以任意修改或者授予此对象相应的权限.Linux的UGO(User, Grou ...

  8. linux下添加删除,修改,查看用户和用户组

    一.组操作 1.创建组: groupadd test #增加一个test组 2.修改组 groupmod -n test2 test #将test组的名子改成test2 3.删除组 groupdel ...

  9. linux下磁盘相关工具(待整理)

    一.概述: fsck tune2fs mke2fs badblocks mkfs* fdisk mount umount mknod e2label blkid hdparm mkswap swapo ...

随机推荐

  1. 给树莓派Raspbian stretch版本修改软件源

    树莓派最新的系统版本是stretch,试了阿里和网易的软件源都不行,最后试了清华的可以 deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbia ...

  2. 一行代码搞定checkbox全选和全不选

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  3. 图解HTTP总结(4)——返回结果的HTTP状态码

    HTTP状态码负责表示客户端HTTP请求的返回结果.标记服务器端的处理是否正常.通知出现的错误等工作. 状态码的类别 2XX 成功 200 OK 表示从客户端发来的请求在服务器端被正常处理了. 在响应 ...

  4. 最小生成数kruskal算法和prim算法

    定义 连通图:在无向图中,若任意两个顶点vivi与vjvj都有路径相通,则称该无向图为连通图. 强连通图:在有向图中,若任意两个顶点vivi与vjvj都有路径相通,则称该有向图为强连通图. 连通网:在 ...

  5. 17-比赛1 B - 子串计算 Chef and his string challenge (string的运用)

    Chef's best friend Jerry gives Chef a string A and wants to know the number of string A that can be ...

  6. mac上MySQLdb问题解决

    早上有个同学问题python访问mysql的问题,之前的写得脚步突然不能运行了,找了很多文章总算解决问题了O(∩_∩)O哈哈~,希望下次不要浪费这么多时间搞这么坑的问题了.   mac上MySQLdb ...

  7. P2341 [HAOI2006]受欢迎的牛(tarjan+缩点)

    P2341 [HAOI2006]受欢迎的牛 题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就是一头明星奶牛.所有奶 牛都是自恋狂,每头奶牛总是喜欢自己的.奶牛之间的“喜欢”是可以传递的 ...

  8. CF6C Alice, Bob and Chocolate

    CF6C Alice, Bob and Chocolate 题目链接 写了一天搜索写的有点累了,就顺手水了一道CF的模拟题 这道题就是简单的模拟整个题的过程,注意最后输出的形式就好了QWQ AC代码如 ...

  9. Ubuntu设置root密码[repost]

    From: http://hi.baidu.com/busybox/item/283e7d31433db7179cc65ef3 安装完Ubuntu后在终端使用命令:su -然后输入密码,总是不正确.原 ...

  10. java 解析/读取 种子/bt/torrent 内容

    碰到不会的技术问题,我还是先度娘.能中文看懂,为什么非要看英文呢. java 解析/读取 种子/bt/torrent  内容,这个度娘给的满意答案并不是很多.GG之后的搜索结果出现了stackover ...