8.3-ACL权限详解(命令篇)

前言

        我们都知道Linux有三种身份(owner,group,other)搭配三种权限(r,w,x)以及三种特殊权限(SUID,SGID,SBIT),

但是某些时候这些组合不能满足复杂的权限需求。


例如

      目录data的权限为:drwxr-x—,所有者与所属组均为root,在不改变所有者和所属组的前提下,要求用户yufei对该

目录有完全访问权限(rwx),但又不能让其他有用完全权限(rwx)。这个要求看似不能实现,这就看出来传统的权限

管理设置有时候也会力不从心。为了解决这样的问题,Linux开发出了一套新的文件系统权限管理方法,叫文件访问

控制列表ACL(Access Control Lists)。这时候,我们就可能通过ACL来实现。


什么是ACL

        ACL是Access Control List的缩写,主要的目的是在提供传统的owner,group,others的read,write,execute权限之外的局

部权限设定。ACL可以针对单个用户,单个文件或目录来进行r,w,x的权限设定,特别适用于需要特殊权限的使用情况。

简单来说,ACL就是可以设定特定用户或用户组对于一个文件或目录的操作权限



1.查看当前分区是否支持ACL权限

[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  3.6G   14G  21% /

[root@localhost ~]# dumpe2fs -l /dev/sda1
...
Default mount options:    user_xattr acl

若没有acl选项,则用以下命令挂载
mount -o remount,acl /dev/sda1

2.查看acl权限

        getfacl file

[root@localhost ~]# getfacl /root/testdir/a 
getfacl: Removing leading '/' from absolute path names
# file: root/testdir/a
# owner: root
# group: root
user::rw-
group::r--
other::r--

3.设定facl权限

setfacl 选项 类型:用户:权限 file
        -m 设定acl权限
        -x 删除指定的acl权限
        -b 删除所有的acl权限
        -d 设定默认acl权限
        -k 删除默认acl权限
        -R 递归设定acl
eg:    setfacl -m u:tom:rw /testdir            #添加tom用户对/testdir有读写权限 
       setfacl -m g:alice:rw /testdir          #添加alice组对/testdir有读写权限

4.删除acl权限
    setfacl -x u:user 文件名    :删除指定的acl权限
    setfacl -b 文件名               :删除文件所有acl权限

[root@localhost ~]# setfacl -x u:tom /testdir/
[root@localhost ~]# setfacl -b /testdir/
[root@localhost ~]# getfacl /testdir/
getfacl: Removing leading '/' from absolute path names
# file: testdir/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

5.修改mask值

    setfacl -m m:rw /testdir

[root@localhost ~]# setfacl -m mask:w /root/acl/
[root@localhost ~]# getfacl /root/acl/
getfacl: Removing leading '/' from absolute path names
# file: root/acl/
# owner: root
# group: root
user::rwx
user:tom:rw-   #effective:-w-
group::r-x   #effective:---
mask::-w-
other::r-x

 

6.递归acl:针对目录下已存在的文件
      setfacl -R -m u:用户名:权限 目录名

[root@localhost ~]# setfacl -R -m u:tom:rw acl/
[root@localhost ~]# getfacl acl/
# file: acl/
# owner: root
# group: root
user::rwx
user:tom:rw-
group::r-x
mask::rwx
other::r-x
[root@localhost ~]# getfacl acl/a 
# file: acl/a
# owner: root
# group: root
user::rw-
user:tom:rw-
group::r--
mask::rw-
other::r--

 

7.默认acl:针对加入到目录的新文件
      setfacl -m d:u:用户名:权限  目录名

新文件没有acl权限
[root@localhost ~]# touch /root/acl/test.txt
[root@localhost ~]# getfacl /root/acl/test.txt
getfacl: Removing leading '/' from absolute path names
# file: root/acl/test.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--
对目录使用默认acl权限
[root@localhost ~]# setfacl -m d:u:tom:rw /root/acl/
[root@localhost ~]# touch /root/acl/test2.txt
[root@localhost ~]# getfacl /root/acl/test2.txt
getfacl: Removing leading '/' from absolute path names
# file: root/acl/test2.txt
# owner: root
# group: root
user::rw-
user:tom:rw-
group::r-x   #effective:r--
mask::rw-
other::r--

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

#getfacl -R /tmp/dir1 > acl.txt
#setfacl -R -b /tmp/dir1
#setfacl -R --set-file=acl.txt /tmp/dir1
#getfacl -R /tmp/dir1

 附:用户对于文件的最终权限要和mask值“相与”才是最后所得权限,“文件所有者”和“其他人”对文件权限不受mask限制。

 

 

 

原创文章,作者:M20-1--孔祥文,如若转载,请注明出处:http://www.178linux.com/28408

(0)
上一篇 2016-08-04 14:39
下一篇 2016-08-04 14:40

相关推荐

  • CentOS6 网络管理之网卡配置及简单路由设置

    CentOS6中关于网络配置的命令有很多,本文将介绍几个平时最长用的几个命令,以及网卡IP地址的配置和简单路由配置。 1、经常使用的查看IP地址命令为 ifconfig,不跟参数的情况下默认查看所有已启用的网卡信息,如下图所示: 如果想查看具体某块网卡信息,则可以在ifconfig后面跟上网卡设备,如只查看eth0的信息则执行:ifconfig eht0 即…

    Linux干货 2016-09-05
  • apache服务器

    一、改变网页的默认位置 1、修改DocumentRoot和Directory,修改新的存放路径为/data/htdocs/ 2、创建/data/htdocs/index.html,注意权限问题 3、注意报错You don't have permission to access /index.html,此时去查看SElinux的状态。命令selinu…

    Linux干货 2016-10-09
  • iptables

    Evernote Export   基于本机服务器的iptables: 创建、重命名、删除自定义chain ~]# iptables -N testchain ~]# iptables -nL Chain INPUT (policy ACCEPT) target     prot opt source    …

    Linux干货 2016-11-20
  • N26 第一周作业

    一、计算机的组成及其功能 计算机:硬件部分、软件部分硬件部分:CPU:运算器和控制器存储器:存储数据输入设备:输入数据输出设备:输出数据软件部分:Kernel:管理和协调硬件,提供基本功能,为应用软件提供平台Application:为某种特定用途开发的软件二、Linux的发行版 Debian全称Debian GNU/Linux,采用Linux作为内核,由De…

    Linux干货 2017-02-24
  • 学习宣言

      人生还有很多精彩时刻,需要你去探寻,linux 就是这个深渊的入口,我其实已迫不及待,伙伴们别怕,跟我来,一路披荆斩棘,踏寻生命的足迹!Fighting!

    Linux干货 2016-10-25