100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > mysql访问控制列表acl_Linux访问控制列表(Access Control List 简称ACL)

mysql访问控制列表acl_Linux访问控制列表(Access Control List 简称ACL)

时间:2020-12-05 17:36:05

相关推荐

mysql访问控制列表acl_Linux访问控制列表(Access Control List 简称ACL)

Linux访问控制列表(Access Control List,简称ACL)

作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.ACL概述

ACL:Access Control List,实现灵活的权限管理

除了文件的所有者,所属组和其它人,可以对更多的用户设置权限

CentOS7 默认创建的xfs和ext4文件系统具有ACL功能

CentOS7 之前版本,默认手工创建的ext4文件系统无ACL功能,需手动增加

tune2fs –o acl/dev/sdb1mount –o acl /dev/sdb1 /mnt/test

ACL生效顺序:所有者,自定义用户,自定义组,其他人

二.为jason用户对某个文件设置ACL权限

[root@.cn ~]# ll /data/total4

-rw-r--r--. 1 jason devops 0 Sep 10 06:34jason.txt-rw-r--r--. 1 root devops 22 Sep 10 07:44root.txt

[root@.cn~]#

[root@.cn~]#

[root@.cn~]# setfacl -m u:jason:- /data/root.txt #这里我们对jason用户设置的权限为空("-"),即无权限访问"/data/root.txt"文件。

[root@.cn~]#

[root@.cn~]# ll /data/total4

-rw-r--r--. 1 jason devops 0 Sep 10 06:34jason.txt-rw-r--r--+ 1 root devops 22 Sep 10 07:44root.txt#大家注意,该文件设置后属性后面的"."变成了"+",说明设置ACL权限啦

[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt #我们可以使用该命令查看相应的ACL设置

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: devops

user::rw-user:jason:---#我们发现jason用户对该文件的权限为0group::r--mask::r--other::r--[root@.cn~]#

[root@.cn~]#

[root@.cn~]# su -l jason

Lastlogin: Tue Sep 10 06:34:17 PDT on pts/0[jason@.cn~]$

[jason@.cn~]$ ll /data/root.txt-rw-r--r--+ 1 root devops 22 Sep 10 07:44 /data/root.txt

[jason@.cn~]$

[jason@.cn~]$ cat /data/root.txtcat: /data/root.txt: Permission denied

[jason@.cn~]$

[jason@.cn~]$ echo "尹正杰到此一游">> /data/root.txt-bash: /data/root.txt: Permission denied

[jason@.cn~]$

三.为属组对某个文件设置ACL权限

[root@.cn ~]# groupadd devops

[root@.cn~]#

[root@.cn~]# idjason

uid=10086(jason) gid=10086(jason) groups=10086(jason)

[root@.cn~]#

[root@.cn~]# usermod -G devops jason#为了测试,我们将jason用户加入devops组

[root@.cn~]#

[root@.cn~]# idjason

uid=10086(jason) gid=10086(jason) groups=10086(jason),10097(devops)

[root@.cn~]#

[root@.cn~]# ll /data/total4

-rw-r--r--. 1 root root 22 Oct 9 05:53root.txt

[root@.cn~]#

[root@.cn~]# getfacl /data/getfacl: Removing leading'/'from absolute path names

#file: data/# owner: root

# group: root

# flags:--t

user::rwx

group::r-x

other::rwx

[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-group::r--other::r--[root@.cn~]#

[root@.cn~]# su -l jason

Lastlogin: Wed Oct 9 05:58:25 CST on pts/1[jason@.cn~]$

[jason@.cn~]$ cat /data/root.txt

尹正杰到此一游

[jason@.cn~]$

[jason@.cn~]$ echo "jason到此一游" >> /data/root.txt #我们发现没有设置ACL权限无法写入数据。-bash: /data/root.txt: Permission denied

[jason@.cn~]$

[jason@.cn~]$ exit

logout

[root@.cn~]#

[root@.cn~]#

[root@.cn~]# setfacl -m g:devops:rw /data/root.txt #我们为devops组添加读写权限

[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-group::r--group:devops:rw-mask::rw-other::r--[root@.cn~]#

[jason@.cn~]$ echo "jason到此一游" >> /data/root.txt#再次写入数据,发现数据写入成功啦!

[jason@.cn~]$

[jason@.cn~]$ cat /data/root.txt

尹正杰到此一游

jason到此一游

[jason@.cn~]$

四.将一个文件的权限复制给另一个文件权限

[root@.cn ~]# setfacl -m u:jason:rw /data/root.txt

[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-user:jason:rw-group::r--group:devops:rw-mask::rw-other::r--[root@.cn~]#

[root@.cn~]# touch /data/a.txt

[root@.cn~]#

[root@.cn~]# getfacl /data/a.txt

getfacl: Removing leading'/'from absolute path names

#file: data/a.txt

# owner: root

# group: root

user::rw-group::r--other::r--[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt | setfacl --set-file=- /data/a.txt#将/data/root.txt文件权限复制给/data/a.txt文件

getfacl: Removing leading'/'from absolute path names

[root@.cn~]#

[root@.cn~]# getfacl /data/a.txt

getfacl: Removing leading'/'from absolute path names

#file: data/a.txt

# owner: root

# group: root

user::rw-user:jason:rw-group::r--group:devops:rw-mask::rw-other::r--[root@.cn~]#

五.清除ACL权限

1>.清除指定用户的ACL权限

[root@.cn ~]# getfacl /data/a.txt

getfacl: Removing leading'/'from absolute path names

#file: data/a.txt

# owner: root

# group: root

user::rw-user:jason:rw-group::r--group:devops:rw-mask::rw-other::r--[root@.cn~]#

[root@.cn~]# setfacl -x u:jason /data/a.txt #清除jason用户的ACL权限。

[root@.cn~]#

[root@.cn~]# getfacl /data/a.txt

getfacl: Removing leading'/'from absolute path names

#file: data/a.txt

# owner: root

# group: root

user::rw-group::r--group:devops:rw-mask::rw-other::r--[root@.cn~]#

2>.清除指定组的ACL权限

1 [root@.cn ~]# getfacl /data/a.txt2 getfacl: Removing leading '/'from absolute path names3 # file: data/a.txt4 # owner: root5 # group: root6 user::rw-

7 group::r--

8 group:devops:rw-

9 mask::rw-

10 other::r--

11

12 [root@.cn ~]#13 [root@.cn ~]# setfacl -x g:devops /data/a.txt #仅仅清除掉devops组的ACL权限14 [root@.cn ~]#15 [root@.cn ~]# getfacl /data/a.txt16 getfacl: Removing leading '/'from absolute path names17 # file: data/a.txt18 # owner: root19 # group: root20 user::rw-

21 group::r--

22 mask::r--

23 other::r--

24

25 [root@.cn ~]#26 [root@.cn ~]#

3>.清除所有ACL权限

[root@.cn ~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-user:jason:rw-group::r--group:devops:rw-mask::rw-other::r--[root@.cn~]#

[root@.cn~]# setfacl -b /data/root.txt #清除所有ACL权限

[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-group::r--other::r--[root@.cn~]#

[root@.cn~]#

六.访问控制列表的注意事项

1>.mask只影响除所有者和other的之外的人和组的最大权限

[root@.cn ~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-group::r--other::r--[root@.cn~]#

[root@.cn~]# setfacl -m mask::rw /data/root.txt #mask需要与用户的权限进行逻辑与运算后,才能变成有限的权限(Effective Permission),用户和组的设置必须存在于mask权限设定范围内才会生效。

[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-group::r--mask::rw-other::r--[root@.cn~]#

2>.--set选项会把原来又的ACL选项都删除,用新的替代,需要注意的是一定要包含UGO的设置,不能像-m一样只是添加ACL就可以

[root@.cn ~]# setfacl -b /data/root.txt

[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-group::r--other::---[root@.cn~]#

[root@.cn~]# setfacl --set u::rw,u:jason:rw,g::r,o::- /data/root.txt

[root@.cn~]#

[root@.cn~]# getfacl /data/root.txt

getfacl: Removing leading'/'from absolute path names

#file: data/root.txt

# owner: root

# group: root

user::rw-user:jason:rw-group::r--mask::rw-other::---[root@.cn~]#

3>.备份和恢复ACL(主要的文件操作命令cp和mv都支持ACL,只是cp命令需要加上-p参数。但是tar等常见的备份工具是不会保留目录和文件的ACL信息)

[root@.cn ~]# getfacl -R /data/ >acl.txt#备份某个目录的文件ACL权限

getfacl: Removing leading'/'from absolute path names

[root@.cn~]#

[root@.cn~]# catacl.txt #查看备份目录的ACL权限信息

#file: data/# owner: root

# group: root

# flags:--t

user::rwx

group::r-x

other::rwx

#file: data//root.txt

# owner: root

# group: root

user::rw-user:jason:rw-group::r--mask::rw-other::---#file: data//a.txt

# owner: root

# group: root

user::rw-group::r--mask::r--other::r--[root@.cn~]#

[root@.cn~]# setfacl -R --set-file=acl.txt /data/#恢复指定目录的ACL权限

[root@.cn~]#

七.小试牛刀

1>.在/testdir/dir里创建新文件自动属于webs组,组apps的成员如tomcat能对这些新文件有读写权限,组dbs的成员如:mysql只能对新文件有读权限,其它用户(不属于webs,apps,dbs)不能访问这个文件夹2>.备份/testdir/dir里所有文件的ACL权限到/root/acl.txt中,清除/test/dir中所有ACL权限,最后还原ACL权限。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。