针对特定的某个用户设置权限的方法如下:
[[email protected] ~]# dmesg | grep -i acl #查看系统是否可以设置ACL,若可以查到下面标红的字样,则代表没问题。[ 1.173259] systemd[1]: systemd 219 running in system mode. (+PAM +AUDIT +SEliNUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +liBCRYPTSETUP +GCRYPT +GNUTLS +‘ACL‘ +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN)[ 2.487295] sgi XFS with ‘ACL‘s,security attributes,no deBUG enabled1、setfacl——设置ACL规则(针对单一用户设置)
setfacl的常用选项如下:
-m:设置后续的ACL参数给文件使用,不可与-x一起使用; -x:删除后续的ACL参数,不可与-m一起使用; -b:删除所有的ACL设置参数; -k:删除默认的ACL参数; -R:递归设置ACL,就是包括子目录都会被应用; -d:设置默认ACL参数,只对目录有效,在该目录新建的数据会引用此默认值;
设置举例:
[[email protected] ~]# touch acl_test1 #创建一个测试文件[[email protected] ~]# setfacl -m u:lv:rw acl_test1 #单独赋予用户“lv”读写权限[[email protected] ~]# ll acl_test1 #查看文件属性,在权限栏最后多了一个“+”,这就是刚设置的ACL-rw-rw-r--+ 1 root root 0 9月 3 08:45 acl_test1[[email protected] ~]# setfacl -m u::rwx acl_test1 #若u后面不写用户,则表示设置该文件的属主权限[[email protected] ~]# ll acl_test1 #会发现属主的权限变成了rwx。-rwxrw-r--+ 1 root root 0 9月 3 08:45 acl_test12、getfacl——查看设置的ACL规则
选项和setfacl基本相同,可以通过man手册来查看具体的使用选项,最主要还是用来查看我们使用setfacl设置的ACL规则;
使用举例:
[[email protected] ~]# getfacl acl_test1 #使用getfacl查看设置的ACL权限# file: acl_test1 #文件名# owner: root #文件属主# group: root #文件属组user::rwx #属主的权限user:lv:rw- #用户“lv”的权限group::r-- #文件属组的权限mask::rw- #此文件默认的有效权限#用户或群组所设置的权限必须要存在于mask的权限设置范围内才会生效other::r-- #其他任何人的权限[[email protected] ~]# ll acl_test1 #使用“ll”命令查看后,进行比较-rwxrw-r--+ 1 root root 0 9月 3 08:45 acl_test13、setfacl和getfacl综合使用举例:
#1、针对有效权限mask的设置方式[[email protected] ~]# setfacl -m m:r acl_test1 #设置该文件的权限仅有读权限(r)。[[email protected] ~]# getfacl acl_test1 #查看# file: acl_test1# owner: root# group: rootuser::rwxuser:lv:rw- #effective:r-- #注释为有效权限只有r(读权限),哪怕用户后面有w(写权限),也不生效group::r--mask::r-- #是因为这里,这里有并且用户也具有的权限,才是有效权限,如这里的“r”权限。other::r--#2、针对特定群组的方式设置权限(删除了原本的文件,又新建了一个acl_test1):[[email protected] ~]# setfacl -m g:mygroup:rx acl_test1 #设置mygroup组有rx权限[[email protected] ~]# getfacl acl_test1 #查看# file: acl_test1# owner: root# group: rootuser::rw-group::r--group:mygroup:r-x #这里就是新设置的权限mask::r-xother::r--#3、让myuser1在/usr/local下面一直具有rx的默认权限[[email protected] ~]# setfacl -m d:u:myuser1:rx /usr/local/ #设置权限[[email protected] ~]# getfacl /usr/local/ #查看getfacl: Removing leading ‘/‘ from absolute path names# file: usr/local/# owner: root# group: rootuser::rwxgroup::r-xother::r-xdefault:user::rwxdefault:user:myuser1:r-x #就是这行咯default:group::r-xdefault:mask::r-xdefault:other::r-x#创建一个目录,并查看是否继承了默认权限[[email protected] ~]# cd /usr/local/[[email protected] local]# mkdir test[[email protected] local]# ls -ld test/ #有“+”的权限,说明继承默认权限了drwxr-xr-x+ 2 root root 6 9月 3 09:51 test/[[email protected] local]# getfacl test #使用getfacl查看# file: test# owner: root# group: rootuser::rwxuser:myuser1:r-xgroup::r-xmask::r-xother::r-xdefault:user::rwxdefault:user:myuser1:r-x #就是这行咯default:group::r-xdefault:mask::r-xdefault:other::r-x#以下为取消用户的某些ACL规则[[email protected] local]# setfacl -x u:myuser1 /usr/local/ #取消myuser1用户对该目录的ACL规则[[email protected] local]# setfacl -x d:u:myuser1 /usr/local/ #取消递归的ACL规则[[email protected] local]# setfacl -m u:myuser1:- /usr/local #使myuser1用户无法使用该目录,在权限字段使用“-”表示即可。
———————— 本文至此结束,感谢阅读 ————————
总结以上是内存溢出为你收集整理的Linux的ACL规则设置——setfacl及getfacl命令的使用详解全部内容,希望文章能够帮你解决Linux的ACL规则设置——setfacl及getfacl命令的使用详解所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)