linux ACL权限规划:getfacl,setfacl使用

                       linux ACL权限规划:getfacl,setfacl使用linux

                          ACL的使用vim

    ACLAccess Control List 主要的目的是提供传统的owner,group,othersread,write,execute权限以外的具体权限设置,ACL能够针对单一用户、单一文件或目录来进行r,w,x的权限控制,对于须要特殊权限的使用情况有必定帮助。如,某一个文件,不让单一的某个用户访问。 ide

   ACL使用两个命令来对其进行控制 测试

     getfacl:取得某个文件/目录的ACL设置项目 this

     setfacl:设置某个文件/目录的ACL设置项目 spa

   

 setfacl 参数 code

  -m:设置后续acl参数  递归

  -x:删除后续acl参数   get

  -b:删除所有的acl参数 权限控制

  -k:删除默认的acl参数

  -R:递归设置acl,包括子目录

  -d:设置默认acl

例:建立一文件test,将其权限修改成777,并查看其默认ACL权限配置

    [root@Self-study ~]# touch /test

    [root@Self-study ~]# chmod 777 /test

    [root@Self-study ~]# getfacl /test             //得到文件的ACL权限

    getfacl: Removing leading '/' from absolute path names

    # file: test                                //文件名

    # owner: root                             //文件所属者

    # group: root                             //文件所属组

    user::rwx                                //文件所属者权限

    group::rwx                               //同组用户权限

    other::rwx                               //其它者权限

[root@Self-study ~]# 

能够看到其它者的权限也是可读可写可执行,能够自行测试,如今咱们修改其ACL策略,使用用户code只有读取的权限

 [root@Self-study ~]# setfacl -m u:code:r /test

[root@Self-study ~]# ll /test

-rwxrwxrwx+ 1 root root 1 Apr 11 07:25 /test            //能够看到权限的最后多了一个+

[root@Self-study ~]# 

如今再次查看一下此文件的ACL属性

[root@Self-study ~]# getfacl /test

getfacl: Removing leading '/' from absolute path names

# file: test

# owner: root

# group: root

user::rwx

user:code:r--                           //能够看到code单独的权限为r--

group::rwx

mask::rwx

other::rwx

 [root@Self-study ~]# 

注:code的权限并非只根据ACL配置来决定的,它是由code用户基本权限与配置的ACL权限的“与”运算决定的,即other:rwx 与 code:r--  = code:r--

如今使用code用户,测试是否可写

 在写文件时,会出现-- INSERT -- W10: Warning: Changing a readonly file提示。

除了对单个用户进行设置外,还能够对用户组、有效权限(mask)进行设置如对用户组设置:    g:[用户组]:[rwx] 

注:有效权限(mask) 即用户或组所设置的权限必需要存在于mask的权限设置范围内才会生效

 如上面的/test文件,已经有了可读权限,若是咱们把它的有效权限修改成只有写权限,则设置的acl权限不在有效权限以内,则用户code就不可能再查看/test文件中的内容了

 [root@Self-study ~]# setfacl -m m:w /test              //设置有效权限为只写

能够查看/test acl属性

[root@Self-study ~]# getfacl /test

getfacl: Removing leading '/' from absolute path names

# file: test

# owner: root

# group: root

user::rwx

user:code:r-- #effective:---

group::rwx #effective:-w-

mask::-w-                       //能够看到有效权限已经修改为功

other::rwx

[root@Self-study ~]# 

使用code用户查看文件内容,首先使用root用户写入一些内容,会使测试更加直观

[root@Self-study ~]# echo "this is a test getfacl " >/test

[code@Self-study ~]$ vim /test 

 "/test" [Permission Denied]                     //能够在最下面看到不容许访问的提示,而且看不到任何内容

取消acl权限

[root@Self-study ~]# setfacl -x u:code /test             //取消/test对用户code的权限

    [root@Self-study ~]# setfacl -x m /test                 //恢复有效权限

    [root@Self-study ~]# getfacl /test               

    getfacl: Removing leading '/' from absolute path names

    # file: test

    # owner: root

    # group: root

    user::rwx

    group::rwx

    other::rwx

    [root@Self-study ~]# ll /test

    -rwxrwxrwx 1 root root 24 Apr 11 08:01 /test              //已经能够正常使用

    [root@Self-study ~]# 

    至于另外的一些参数,本身尝试使用!!

相关文章
相关标签/搜索