Linux下的ACL
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的更多相关文章
- linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制)
linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制) 发表于2012//07由feng linux 本身的ugo rwx的权限,对于精确的权限控制很是力不从心的,ac ...
- Shell初学(八)linux下的ACL
[1]ACL的作用 简单直接解释一下ACL的作用,即把权限的个别化额外添加. 可以解决如下问题~~比如: [1.1]基于用户: 我有10个用户a1-a10,我有一个文件夹/tmp/test,我想给a1 ...
- 构建LINUX下的入侵检测系统——LIDS 系统管理命令--vlock
构建LINUX下的入侵检测系统——LIDS 系统管理命令--vlock http://blog.chinaunix.net/uid-306663-id-2440200.html LIDS官方网站: ...
- Linux下Nagios的安装与配置
一.本文说明 本文是在参考:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html David_Tang文章以及网上的一些资料完 ...
- linux下恢复误删除的文件方法(ext2及ext3)
linux下恢复误删除的文件方法(ext2及ext3) 2009-12-19 15:23:47 分类: LINUX 如果是ext2文件系统的,直接用debugfs是可以恢复出来的,但对于ext3,d ...
- Linux下部署Symfony2对app/cache和app/logs目录的权限设置
在linux下部署完Symfony2,可能在访问的时候会报app/logs或者app/cache目录没有写权限的错误.在linux下,如果我们在命令行登陆的用户和web应用服务器(apache.ngi ...
- Linux UGO和ACL权限管理
自主访问控制(Discretionary Access Control, DAC)是指对象(比如程序.文件.进程)的拥有者可以任意修改或者授予此对象相应的权限.Linux的UGO(User, Grou ...
- linux下添加删除,修改,查看用户和用户组
一.组操作 1.创建组: groupadd test #增加一个test组 2.修改组 groupmod -n test2 test #将test组的名子改成test2 3.删除组 groupdel ...
- linux下磁盘相关工具(待整理)
一.概述: fsck tune2fs mke2fs badblocks mkfs* fdisk mount umount mknod e2label blkid hdparm mkswap swapo ...
随机推荐
- python数据类型的转换
- asciinema使用
asciinema让您轻松记录终端会话,并在终端和网页浏览器中重播它们. 安装最新版本: sapt-get install asciinema 记录你的第一个终端视频: asciinema rec f ...
- Web前端开发面试技巧
Web前端开发面试技巧 面试前端工程师对我来说是一件非常有意思的事,因为面试过程很大程度上也是自我提升的过程.无论大公司还是小公司,之所以在如何招聘到真正有能力的,前端工程师方面会遇到同样的问题. 近 ...
- 子查询,用户管理,pymysql使用
当我们的一条记录 分散不同的表中时,就需要进行多表查询例如 一对一 一对多 多对多 1.笛卡尔积查询 意思就是将两个表中的所有数据 全部关联在一起例如A表有两条 B表有三条 一共有6条会产生大量的错误 ...
- C语言字符篇(三)字符串比较函数
#include <string.h> int strcmp(const char *s1, const char *s2); 比较字符串s1和s2 int strncmp(const ...
- python——numpy_1图像基本操作
1.图像的数组表示: from PIL import Image from pylab import * from numpy import * im = array(Image.open('E:\P ...
- U2
android的XML文件(包括layout下的和values下的)注释一般采用 <!--注释内容 -->的方式进行,也就是说,采用//是行不通的,不信你可以试试看. 在XML中, ...
- 牛客暑假多校第一场J-Different Integers
一.题目描述: 链接:https://www.nowcoder.com/acm/contest/139/JGiven a sequence of integers a1, a2, ..., an an ...
- perl语言入门总结-第5章-输入输出
读取标准输入 chomp($line = <STDIN>); #去掉后面的换行 while (defined($line = <STDIN>)) { print "I ...
- Java线程和多线程(七)——ThreadLocal
Java中的ThreadLocal是用来创建线程本地变量用的.我们都知道,访问某个对象的所有线程都是能够共享对象的状态的,所以这个对象状态就不是线程安全的.开发者可以通过使用同步来保证线程安全,但是如 ...