不同的用户对某个文件有不同的权限 ACL应用实例

东坡下载 2011年04月26日 11:09:45

      ACL可以对某个文件设置该文件具体的某些用户的权限,意思就是通过ACL可以对一个文件权限做扩展,可以不同的用户对某个文件有不同的权限。
      语法
      getfacl <文件名>
      获取文件的访问控制信息
      setfacl设置文件的acl
      -m 修改文件的acl
      -x 取消对文件的设置
      setfacl –m u:用户名:权限 文件名
      setfacl –m g:组 名:权限 文件名
      setfacl –x 用户名文件名
      setfacl –x g:组名文件名
      [root@beryl ~]# touch file
      [root@beryl ~]# getfacl file
      # file: file
      # owner: root
      # group: root
      user::rw-
      group::r--
      other::r--
      现在我们把、natasha用户加上一个RWX的权限:setfacl -m u:natasha:rwx file
      [root@beryl ~]# setfacl -m u:natasha:rwx file
      [root@beryl ~]# ll file
      -rw-rwxr--+ 1 root root 0 Apr 16 09:08 file
      [root@beryl ~]# getfacl file
      # file: file
      # owner: root
      # group: root
      user::rw-
      user:natasha:rwx
      group::r--
      mask::rwx
      other::r--
      和设置ACL前有哪些区别?
      用ll看,权限后面有个+就可能是设置了文件权限,所以没必要没个文件都用gefacl 去看
      在查看acl的内容时候,我们看见多了行,natasha 用户有了rwx的权限
      然后我们用相似的命令把natasha组也加进去.给他RW的权限:setfacl -m g:natasha:rw file
      [root@beryl ~]# setfacl -m g:natasha:rw file
      [root@beryl ~]# ll file
      -rw-rwxr--+ 1 root root 0 Apr 16 09:08 file
      [root@beryl ~]# getfacl file
      # file: file
      # owner: root
      # group: root
      user::rw-
      user:natasha:rwx
      group::r--
      group:natasha:rw-
      mask::rwx
      other::r--
      现在我们取消redhat用户的权限:setfacl -x natasha file
      [root@beryl ~]# setfacl -x natasha file
      [root@beryl ~]# getfacl file
      # file: file
      # owner: root
      # group: root
      user::rw-
      group::r--
      group:natasha:rw-
      mask::rw-
      other::r--
      我们发现user:natasha:rwx这一行已经没有了
      [root@beryl ~]# setfacl -x g:redhat file
      [root@beryl ~]# getfacl file
      # file: file
      # owner: root
      # group: root
      user::rw-
      group::r--
      group:natasha:rw-
      mask::rw-
      other::r--
      现在group:natasha:rw-这一行也没有了
      注意,撤消ACL操作:
      对用户直接加用户名字就可以了
      对组,在前面加g:组名
      现在我们也取消redhat组的权限:setfacl -x g:natasha file