wordpress重新打开多站点,网站做视频怎么赚钱的,百度权重查询方法,企业微信收费标准一年多少钱今天给伙伴们分享一下Linux ACL 访问控制#xff0c;希望看了有所收获。 我是公众号「想吃西红柿」「云原生运维实战派」作者#xff0c;对云原生运维感兴趣#xff0c;也保持时刻学习#xff0c;后续会分享工作中用到的运维技术#xff0c;在运维的路上得到支持和共同进步…今天给伙伴们分享一下Linux ACL 访问控制希望看了有所收获。 我是公众号「想吃西红柿」「云原生运维实战派」作者对云原生运维感兴趣也保持时刻学习后续会分享工作中用到的运维技术在运维的路上得到支持和共同进步 如果伙伴们看了文档觉得有用欢迎大家关注我的公众号获取相关文档。爱运维爱生活。 一、ACL访问控制概述 基础权限UGO、特殊权限所有的权限是针对某一类用户设置的, 如果希望对文件进行自定义权限控制就需要用到文件的访问控制列表ACL UGO设置基本权限: 只能一个用户一个组和其他人 ACL设置基本权限 r、w、x 设定acl只能是root管理员用户. 相关命令: getfacl , setfacl getfacl 命令用于查看文件或目录当前设定的 ACL 权限信息。该命令的基本格式为
[rootedenluo.com ~]# getfacl 文件名setfacl 命令可直接设定用户或群组对指定文件的访问权限。此命令的基本格式为
[rootedenluo.com ~]# setfacl 选项 文件名命令可以使用的所用选项及功能
选项功能-m设定 ACL 权限。如果是给予用户 ACL 权限参数则使用 “u:用户名:权限” 的格式例如 setfacl -m u:st:rx /project 表示设定 st 用户对 project 目录具有 rx 权限如果是给予组 ACL 权限参数则使用 “g:组名:权限” 格式例如 setfacl -m g:tgroup:rx /project 表示设定群组 tgroup 对 project 目录具有 rx 权限。-x删除指定用户参数使用 u:用户名或群组参数使用 g:群组名的 ACL 权限例如 setfacl -x u:st /project 表示删除 st 用户对 project 目录的 ACL 权限。-b删除所有的 ACL 权限例如 setfacl -b /project 表示删除有关 project 目录的所有 ACL 权限。-d设定默认 ACL 权限命令格式为 “setfacl -m d:u:用户名:权限 文件名”如果是群组则使用 d:g:群组名:权限只对目录生效指目录中新建立的文件拥有此默认权限例如 setfacl -m d:u:st:rx /project 表示 st 用户对 project 目录中新建立的文件拥有 rx 权限。-R递归设定 ACL 权限指设定的 ACL 权限会对目录下的所有子文件生效命令格式为 “setfacl -m u:用户名:权限 -R 文件名”群组使用 g:群组名:权限例如 setfacl -m u:st:rx -R /project 表示 st 用户对已存在于 project 目录中的子文件和子目录拥有 rx 权限。-k删除默认 ACL 权限。
acl基本使用方式
环境准备
[rootedenluo.com ~]# cp /etc/passwd /root/passwd文件在没有设定acl, 看到的和传统权限是一样
[rootedenluo.com ~]# ll passwd
-rw-r--r-- 1 root root 0 10-26 13:59 /home/test.txt
使用getacl查看权限
[rootedenluo.com ~]# getfacl passwd
# file: passwd
# owner: root
# group: root
user::rw- //文件owner权限
group::r-- //文件拥有组权限
other::r-- //其他人权限1、设定acl权限案例
要求
-rw-r--r-- 1 root root 1380 Feb 27 11:25 passwd
alice 拥有读写权限 rw
edenluo 没有任何权限 -
jack 组拥有读权限 r
匿名用户拥有读写权限 rw
1、建立相关用户
[rootedenluo.com ~]# useradd alice
[rootedenluo.com ~]# useradd edenluo
[rootedenluo.com ~]# useradd jack
增加用户 alice 权限
[rootedenluo.com ~]# setfacl -m u:alice:rw passwd
增加用户 edenluo 权限
[rootedenluo.com ~]# setfacl -m u:edenluo:- passwd
增加匿名用户权限
[rootedenluo.com ~]# setfacl -m o::rw passwd
增加组权限
[rootedenluo.com ~]# setfacl -m g:jack:r passwd注意: 如果用户同时属于不同的两个组并且两个组设定了acl访问控制 1、根据acl访问控制优先级进行匹配规则 2、如有用户拥有多个组的权限不同的权限优先使用最高权限模糊匹配
2、查看acl权限
[rootedenluo.com ~]# ll passwd
-rw-rw-rw- 1 root root 1531 Jan 26 07:52 passwd
[rootedenluo.com ~]# getfacl passwd
# file: passwd
# owner: root
# group: root
user::rw-
user:edenluo:---
user:alice:rw-
group::r--
group:jack:r--
mask::rw-
other::rw-3、移除acl权限
移除jack组的acl权限
[rootedenluo.com ~]# setfacl -x g:jack passwd
移除edenluo.com用户的acl权限
[rootedenluo.com ~]# setfacl -x u:edenluo passwd
移除文件和目录所有acl权限
[rootedenluo.com ~]# setfacl -b passwd//移除默认的acl
[rootedenluo.com ~]# setfacl -k dir4、查看acl帮助
EXAMPLES 示例
[rootedenluo.com ~]# man setfacl
复制 file1 的 ACL 权限给 file2
[rootedenluo.com ~]# setfacl -m u:alice:rw,u:edenluo:r,g:jack:rw file1
[rootedenluo.com ~]# getfacl file1 |setfacl --set-file- file2二、ACL高级特性MASK
mask用于临时降低用户或组的权限但不包括文件的所有者和其他人。mask最主要的作用是用来决定用户的最高权限。mask默认不会对匿名用户降低权限所以为了便于管理文件的访问控制建议匿名用户的权限置为空
临时降低用户或组权限
[rootedenluo.com ~]# setfacl -m mask::rw filename小结
1、mask会影响哪些用户除了所有者和其他人。
2、mask权限决定了用户访问文件时的最高权限。(如何影响)
3、mask用于临时降低用户访问文件的权限。(mask做什么)
4、任何重新设置acl访问控制会清理mask所设定的权限。
三、ACL高级特性Default default: 继承(默认) alice能够对/opt目录以及以后在/opt目录下新建的文件有读、写、执行权限
赋予 alice 对/home 读写执行权限
[rootedenluo.com ~]# setfacl -R -m u:alice:rwX /opt
赋予 alice 对以后在/home 下新建的文件有读写执行权限(使 alice 的权限继承)
[rootedenluo.com ~]# setfacl -m d:u:alice:rwX /opt
检查对应的权限
[rootedenluo.com ~]# getfacl /opt/
getfacl: Removing leading / from absolute path names
# file: opt/
# owner: root
# group: edenluo.com
user::rwx
user:alice:rwx
group::rwx
mask::rwx
other::rwx
default:user::rwx
default:user:alice:rwx
default:group::rwx
default:mask::rwx
default:other::rwx四、ACL访问控制实践案例
案例1: 将新建文件的属性修改tom:admin, 权限默认为644要求: tom对该文件有所有的权限, mary可以读写该文件, admin组可以读写执行该文件, jack只读该文件, 其他人一律不能访问该文件
实验前, 建立几个普通用户
[rootedenluo.com ~]# useradd tom
[rootedenluo.com ~]# useradd bean
[rootedenluo.com ~]# useradd mary
[rootedenluo.com ~]# useradd jack
[rootedenluo.com ~]# useradd sutdent
[rootedenluo.com ~]# groupadd admin
[rootedenluo.com ~]# gpasswd -a mary admin
[rootedenluo.com ~]# gpasswd -a bean admin//检查用户属性
[rootedenluo.com ~]# id tom
uid1004(tom) gid1004(tom) groups1004(tom)
[rootedenluo.com ~]# id mary
uid1006(mary) gid1006(mary) groups1006(mary),1007(admin)
[rootedenluo.com ~]# id bean
uid1005(bean) gid1005(bean) groups1005(bean),1007(admin)
[rootedenluo.com ~]# id jack
uid1002(jack) gid1002(jack) groups1002(jack)
[rootedenluo.com ~]# id sutdent
uid1007(sutdent) gid1008(sutdent) groups1008(sutdent)//准备相关文件
[rootedenluo.com ~]# cp /etc/passwd /root/
[rootedenluo.com ~]# chown tom:admin passwd
[rootedenluo.com ~]# chmod 644 passwd//检查设定前的acl列表
[rootedenluo.com ~]# getfacl passwd
# file: passwd
# owner: tom
# group: admin
user::rw-
group::r--
other::r--//设定acl权限
[rootedenluo.com ~]# setfacl -m u::rwx,u:mary:rw,u:jack:r,g:admin:rwx,o::- passwd//检查acl权限
[rootedenluo.com ~]# getfacl passwd
# file: passwd
# owner: tom
# group: admin
user::rwx
user:jack:r--
user:mary:rw-
group::r--
group:admin:rwx
mask::rwx
other::---acl的控制规则是从上往下匹配 1.tom由于是文件的拥有者所以直接按照user::rwx指定的权限去操作 2.mary用户从上往下寻找匹配规则发现user:mary:rw-能够精确匹配mary用户尽管mary属于admin组同时admin组有rwx的权限但是由于mary用户的规则在前面所有优先生效。 3.bean由于找不到精确匹配的规则而bean是属于admin组根据文件的定义该文件是属于admin组所以bean的权限是按照group:admin:rwx的权限去操作。 4.jack用户从上往下寻找匹配规则发现user:jack:r--能够精确匹配jack用户。 5.student用户找不到精确匹配的user定义规则, 也找不到相关组的定义规则最后属于other。 案例2: lab acl setup
controller组成员有:student
sodor组成员有:thomas,james
目录: /shares/steamies
文件: /shares/steamies/file
脚本: /shares/steamies/test.sh
controller属于该目录的所属组, 新建文件必须属于controller组
sodor组的成员对该目录拥有rwx权限
sodor组成员james对该目录及子目录(包括以后新建立的文件)没有任何权限实际操作
准备用户
[rootedenluo.com ~]# groupadd controller
[rootedenluo.com ~]# groupadd sodor
[rootedenluo.com ~]# useradd student -G controller
[rootedenluo.com ~]# useradd thomas -G sodor
[rootedenluo.com ~]# useradd james -G sodor
准备目录
[rootedenluo.com ~]# mkdir /shares/steamies -p
[rootedenluo.com ~]# echo file /shares/steamies/file
[rootedenluo.com ~]# echo echo 123 /shares/steamies/test.sh
[rootedenluo.com ~]# chmod 755 /shares/steamies/test.sh
[rootedenluo.com ~]# chown -R :controller /shares/steamies/
[rootedenluo.com ~]# chmod gs /shares/steamies/
设定权限(X表示,如果原本有执行权限就保留,如果没有则不添加)
[rootedenluo.com ~]# setfacl -R -m g:sodor:rwX,u:james:- /shares/steamies/
设定继承规则
[rootedenluo.com ~]# setfacl -R -m d:g:sodor:rwX,d:u:james:- /shares/steamies/
[rootedenluo.com steamies]# getfacl /shares/steamies/
getfacl: Removing leading / from absolute path names
# file: shares/steamies/
# owner: root
# group: controller
# flags: -s-
user::rwx
user:james:---
group::r-x
group:sodor:rwx
mask::rwx
other::r-x
default:user::rwx
default:group::r-x
default:group:sodor:rwx
default:mask::rwx
default:other::r-x如果有版帮助帮忙免费的关注一下**公众号「想吃西红柿」「云原生运维实战派」**后续会有更多实用的运维技术分享给伙伴们您的关注就是我最大的成就。