Linux ACL权限

 

Linux ACL权限

Linux的权限非常重要,我们之前所说的几种权限中,但是并不能只针对一个用户或者一个组进行单独设置,而ACL权限可以帮助我们实现这个功能,比如说有一个文件的所有者和所有者组都是a,这个文件的权限是660,我可以让b这个用户可以对文件进行读写的操作,而b这个用户并不属于a组的成员。那我们来看下如何使用

ACL权限的设置和查看

如果要使用acl权限,首先要确定你的文件系统支持acl权限,如果再Default mount options字段出现acl字样就意味着你的文件系统支持acl,不过在CentOS8中默认是都支持的。

[root@muqing test]# tune2fs -l /dev/sda1tune2fs 1.44.3 (10-July-2018)Filesystem volume name:   <none>Last mounted on:          /bootFilesystem UUID:          be03eaec-6474-42ea-8f79-06e7198f5155Filesystem magic number:  0xEF53Filesystem revision #:    1 (dynamic)Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csumFilesystem flags:         signed_directory_hash Default mount options:    user_xattr aclFilesystem state:         clean...

配置acl权限我们需要使用两个命令一个是setfacl用来设置acl权限,另一个是getfacl用来查看acl权限

  • setfacl命令:设置文件或文件夹的ACL权限

命令选项:-m :设置acl-x :删除指定的acl-b :删除所有的acl
  • getfacl命令:用来查看文件的acl权限现在我们来看下如何设置

[root@muqing test]# lsfile  file1[root@muqing test]# ll file1-rw-r--r-- 1 root root 0 10月 18 02:48 file1[root@muqing test]# setfacl -m u:oracle:rw file1 为指定的用户配置一个rw的权限[root@muqing test]# setfacl -m u::rwx file1      如果没有指定用户则默认是为该文件的所有者设置[root@muqing test]# ll file1-rwxrw-r--+ 1 root root 0 10月 18 02:48 file1    所有者权限变成的rwx而且后面多了一个+号

你会发现使用ll(等同于ls -l)命令查看时会发现多了一个+号,这只是提醒我们此文件被设置了acl权限,但是具体是什么样的,我们还需要使用getfacl来查看

[root@muqing test]# getfacl file1# file: file1           文件名# owner: root           所有者# group: root           所有者组user::rwx               user:后面是空的,代表的是所有者的权限user:oracle:rw-         我们之前给额外用户设置的权限group::r--              所有者组的权限mask::rw-               默认的有效权限other::r--              其他人的权限

以上是我们针对一个额外的用户设置的权限,同理可以设置针对组和其他人的acl权限

为不同用户或组设置不同权限

[root@muqing test]# setfacl -m g:oracle:rw file1[root@muqing test]# setfacl -m o:rw file1[root@muqing test]# getfacl file1# file: file1# owner: root# group: rootuser::rwxuser:oracle:rw-group::r--group:oracle:rw-mask::rw-other::rw-

删除指定的acl

[root@muqing test]# setfacl -x u:oracle file1        删除用户acl[root@muqing test]# getfacl file1# file: file1# owner: root# group: rootuser::rwxgroup::r--group:oracle:rw-mask::rw-other::rw-[root@muqing test]# setfacl -x g:oracle file1        删除组acl[root@muqing test]# getfacl file1# file: file1# owner: root# group: rootuser::rwxgroup::r--mask::r--other::rw-[root@muqing test]# chmod o=r file1              删除其他人直接使用chmod就可以[root@muqing test]# ll file1-rw-r--r-- 1 root root 0 10月 18 04:21 file1[root@muqing test]# getfacl file1# file: file1# owner: root# group: rootuser::rw-group::r--other::r--

删除所有acl

[root@muqing test]# setfacl -m u:oracle:rw,g:oracle:rw,o:rwx file1[root@muqing test]# getfacl file1# file: file1# owner: root# group: rootuser::rw-user:oracle:rw-group::r--group:oracle:rw-mask::rw-other::rwx[root@muqing test]# setfacl -b file1[root@muqing test]# getfacl file1# file: file1# owner: root# group: rootuser::rw-group::r--other::rwx

原创文章,作者:速盾高防cdn,如若转载,请注明出处:https://www.sudun.com/ask/57219.html

(0)
速盾高防cdn的头像速盾高防cdn
上一篇 2024年5月14日 下午2:50
下一篇 2024年5月14日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注