博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux学习记录--ACL权限控制
阅读量:4212 次
发布时间:2019-05-26

本文共 3694 字,大约阅读时间需要 12 分钟。

ACL权限控制

设置ACL权限:setfacl

查看ACL权限:getfacl

ACL权限控制主要目的是提供传统的owner,group,other的read,wirte,execute权限之外的具体权限设置,可以针对单一用户或组来设置特定的权限

比如:某一目录权限为

drwx------ 2 root root 4096 03-10 13:51./acldir

用户user对此目录无任何权限因此无法进入此目录,ACL可单独为用户user设置这个目录的权限,使其可以操作这个目录

 

ACL启动

要使用ACL必须要有文件系统支持才行,目前绝大多数的文件系统都会支持,EXT3文件系统默认启动ACL的

 

查看文件系统是否支持ACL

[root@localhost tmp]# dumpe2fs -h /dev/sda2dumpe2fs 1.39 (29-May-2006)……sparse_super large_fileDefault mount options:    user_xattr acl

加载ACL功能

如果UNIX LIKE支持ACL但是文件系统并不是默认加载此功能,可自己进行添加

[root@localhost tmp]# mount -o remount,acl /[root@localhost tmp]# mount/dev/sda2 on / type ext3 (rw,acl)

同样也可以修改磁盘挂在配置文件设置默认开机加载

[root@localhost tmp]# vi /etc/fstabLABEL=/                 /                       ext3    defaults,acl        1 1

查看ACL权限

 

语法:getfacl filename

设置ACL权限

语法:setfacl [-bkRd]  [-m|-x acl 参数]  目标文件名

选项与参数:

-m:设置后续的acl参数,不可与-x一起使用

-x: 删除后续的acl参数,不可与-m一起使用

-b:删除所有的acl参数

-k:删除默认的acl参数

-R:递归设置acl参数

-d:设置默认acl参数,只对目录有效

 

针对特殊用户

设置格式:u:用户账号列表:权限

权限:rwx的组合形式

如用户列表为空,代表设置当前文件所有者权限

 

举例:

[root@localhost tmp]# mkdir -m 700 ./acldir; ll -d ./acldir drwx------ 2 root root 4096 03-10 13:51 ./acldir[root@localhost tmp]# su tkf[tkf@localhost tmp]$ cd ./acldir/bash: cd: ./acldir/: 权限不够  =>用户无X权限[tkf@localhost tmp]$ exitexit[root@localhost tmp]# setfacl -m u:tkf:x ./acldir/ =>针对用户tkf设置acldir目录的权限为x[root@localhost tmp]# ll -d ./acldir/drwx--x---+ 2 root root 4096 03-10 13:51 ./acldir/ =>通过ACL添加权限在权限末尾会增加多个一个“+”同时文件原本权限也发生变化。=>可通过getfacl查看原始目录权限[root@localhost tmp]# getfacl ./acldir/# file: acldir# owner: root# group: rootuser::rwxuser:tkf:--x  =>记录tkf用户针对此目录有acl权限group::---mask::--xother::---=>这里需要特殊说明,只是tkf这个用户具有X权限,其他用户还是无权限的[root@localhost tmp]# su tkf[tkf@localhost tmp]$ cd ./acldir/[tkf@localhost acldir]$ =>用户tkf可以具有x权限可以进入目录

针对特定用户组

设置格式:g:用户组列表:权限

权限:rwx的组合形式

如用户组列表为空,代表设置当前文件所属用户组权限

举例:

[root@localhost tmp]# setfasetfacl   setfattr  [root@localhost tmp]# setfacl -m g:users:rx ./acldir/[root@localhost tmp]# getfacl ./acldir/# file: acldir# owner: root# group: rootuser::rwxuser:tkf:--xgroup::--- => 其他用户组(非acl设置)的权限group:users:r-x => 记录users用户组针对此目录有acl权限mask::r-xother::---

针对有效权限设置

有效权限(mask)就是acl权限设置的极限值,也就是你所设置的acl权限一定是mask的一个子集,如果超出mask范围会将超出的权限去掉

设置格式:m:权限

权限:rwx的组合形式

举例:
[root@localhost tmp]# setfacl -m m:x ./acldir/[root@localhost tmp]# getfacl ./acldir/# file: acldir# owner: root# group: rootuser::rwxuser:tkf:--xgroup::r-x                      #effective:--xgroup:users:r-x                 #effective:--xmask::--xother::---

针对默认权限设置

我们前面都是针对一个目录为一个用户(组)设置特定权限,但是如果这个目录下在新创建的文件是不具有这些针对这个用户的特定权限的。为了解决这个问题,就需要设置默认acl权限,使这个目录下新创建的文件有和目录相同的ACL特定权限

 

设置格式:d:[u|g]:用户(组)列表:权限

 

举例

[root@localhost tmp]# mkdir -m 711 ./defdir[root@localhost tmp]# setfacl -m u:tkf:rxw ./defdir[root@localhost tmp]# ll -d ./defdir/drwxrwx--x+ 2 root root 4096 03-10 15:23 ./defdir/=>目录权限具有acl特定权限(后面+)[root@localhost tmp]# touch ./defdir/a.file;ll ./defdir/-rw-r--r--  1 root root 0 03-10 15:25 a.file=>新创建的文件不具有acl特定权限(后面无+)[root@localhost tmp]# setfacl -m d:u:tkf:rxw ./defdir=>设置默认权限[root@localhost tmp]# getfacl ./defdir/# file: defdir# owner: root# group: rootuser::rwxuser:tkf:rwxgroup::--xmask::rwxother::--xdefault:user::rwxdefault:user:tkf:rwxdefault:group::--xdefault:mask::rwxdefault:other::--x[root@localhost tmp]# touch ./defdir/b.file;ll ./defdir/-rw-r--r--  1 root root 0 03-10 15:25 a.file-rw-rw----+ 1 root root 0 03-10 15:26 b.file=>新创建文件默认带有acl特定权限[root@localhost tmp]# getfacl ./defdir/b.file # file: defdir/b.file# owner: root# group: rootuser::rw-user:tkf:rwx                    #effective:rw-group::--x                      #effective:---mask::rw-other::---=>这快我有个疑问,为什么mask值是rw,我猜测和文件最大权限有关,=>对于文件来时默认最大权限是666即UMASK为0000.那个对于可执行文件来说=>没有X,难道还需要使用chmod设置? 疑问!!

转载地址:http://udumi.baihongyu.com/

你可能感兴趣的文章
Curl实现web serivce调试调用
查看>>
Tomcat NioEndPoint初探
查看>>
Tomcat NIO/APR对静态资源提速
查看>>
Servlet Filter与Spring interceptor的执行顺序
查看>>
使用HttpServletResponseWrapper获取渲染jsp以后的html
查看>>
Tomcat的ThreadLocalLeakPreventionListener工作原理
查看>>
利用springMVC的interceptor实现页面性能监控(Filter亦可)
查看>>
SpringMVC 拦截器实现分析
查看>>
初始化(Map,List)容器类的容量会有一定的性能提升
查看>>
StringBuffer与StringBuilder浅析
查看>>
BoneCP数据源记录SQl比hibernate的show sql好用
查看>>
对Cookie的一点认识
查看>>
说一说hibernate的Get和Load
查看>>
如何修改tomcat的server信息增加服务器的安全
查看>>
浅谈tomcat的ThreadLocalLeakPreventionListener实现原理
查看>>
说一下多线程中用到的join
查看>>
扩展hibernate Criteria的Order使其支持sql片段(oracle)
查看>>
spring+mybatis利用interceptor(plugin)实现数据库读写分离
查看>>
NIO[SelectableChannel.register和Selector.select会有锁等待冲突]
查看>>
httpclient3.1的relaseConnection的misunderstand
查看>>