|
这里总结一下 ACL 的一些细节问题。
先用一个普通的用户在 /tmp 下建立一个目录:
为这个目录添加一条默认规则,该规则指定 sky 这个用户具有 u 的 rwx 权限:注意,这里 只是添加了规则,但并没有真正时 sky 这个用户的权限生效。如果希望同时也生效,那么使用下面的方式:即默认规则与实际添加之间使用逗号隔开。
查看 beyes_dir 目录的 ACL 规则:[beyes@groad.net tmp]$ getfacl --omit-header beyes_dir/
user::rwx
group::rwx
other::r-x
default:user::rwx
default:user:sky:rwx
default:group::rwx
default:mask::rwx
default:other::r-x 从上面可以看到,默认规则上的权限是和传统权限一样的。这里要注意一个默认掩码 mask ,目录在被设置默认规则时它就会被初始化为 rwx 。
传统权限对默认规则的影响
下面使用 chmod 先去掉该目录的 u 的 x 和 g 的 w 权限:
然后再设置该目录上的默认权限:
然后查看一下目录上的 ACL 默认规则:[beyes@groad.net tmp]$ getfacl beyes_dir/
# file: beyes_dir/
# owner: beyes
# group: beyes
user::rw-
user:sky:rwx
group::r-x
mask::rwx
other::r-x
default:user::rw-
default:user:sky:rwx
default:group::r-x
default:mask::rwx
default:other::r-x 由输出可以看到,默认规则跟随传统权限而改变,但 mask 仍然不变。
这里需要注意的是,先使用 chmod 改变目录的传统权限,然后再添加 ACL 默认规则,这样默认规则权限才会跟随传统权限的变化。反过来,只会改变传统权限,而不会改变默认规则,比如:[beyes@groad.net tmp]$ chmod u-w beyes_dir/
[beyes@groad.net tmp]$ getfacl beyes_dir/
# file: beyes_dir/
# owner: beyes
# group: beyes
user::r--
user:sky:rwx
group::r-x
mask::rwx
other::r-x
default:user::rw-default:user:sky:rwx #没有改变
default:group::r-x
default:mask::rwx
default:other::r-x
由此可见,默认 ACL 权限不会因为中途改变目录的传统权限而改变。
下面考察一下在设置了默认 ACL 权限目录下创建文件及子目录时的情况。
现在假设 beyes_dir 目录的传统权限仍为 rwxrwxr-x ,而默认 ACL 权限被设置为:setfacl -m d:u:sky:rwx,u:sky:rwx beyes_dir/。
现在使用属主用户 beyes 在其下建立一个普通文件:上面显示的是 1.txt 的传统权限。下面看一下它的 ACL 权限:[beyes@groad.net beyes_dir]$ getfacl --omit-header 1.txt
user::rw-
user:sky:rwx #effective:rw-
group::rwx #effective:rw-
mask::rw-
other::r-- 这里有几个地方需要注意:
1. 掩码 mask 变成了 rw- ,而没有像想象中的那样继承 beyes_dir 的 rwx 。
实际上,在 beyes_dir 所建立的普通文件的有效掩码是受其用户组权限影响的。下面做一个实验,比如先将 1.txt 的用户组权限 rw- 中的 w 去掉,然后再观察 ACL 权限: [beyes@groad.net beyes_dir]$ chmod g-w 1.txt
[beyes@groad.net beyes_dir]$ getfacl 1.txt
# file: 1.txt
# owner: beyes
# group: beyes
user::rw-
user:sky:rwx #effective:r--
group::rwx #effective:r--
mask::r--
other::r--
#=========================注意掩码发生了变化,再改变一次===============================
[beyes@groad.net beyes_dir]$ chmod g+x 1.txt
[beyes@groad.net beyes_dir]$ getfacl 1.txt
# file: 1.txt
# owner: beyes
# group: beyes
user::rw-
user:sky:rwx #effective:r-x
group::rwx #effective:r-x
mask::r-x
other::r--
2. 实际 ACL 权限。
实际 ACL 权限受到掩码的影响。观察输出中的注释部分可以清除得得到最后的实际权限。
3. 1.txt 中的 user::rw- ,group::rwx,other::r-- 是从何而来?
在 1.txt 中,user 的权限是 rw- ,它同样不受 beyes_dir 目录中默认权限的影响,因为默认权限是 rwx,而它传统权限为 rw-,从文件属主优先级来看,1.txt 就应该直接继承其属主的传统权限。我们可以验证一下:[beyes@groad.net beyes_dir]$ chmod u-w 1.txt
[beyes@groad.net beyes_dir]$ getfacl 1.txt
# file: 1.txt
# owner: beyes
# group: beyes
user::r--
user:sky:rwx #effective:r-x
group::rwx #effective:r-x
mask::r-x
other::r--
那么 gourp::rwx 为什么是 rwx 而不是文件本身用户组的 rw- ?
group 的权限这里是 rwx,而文件本身用户组的权限为 rw- 。实际上,这里 group 权限继承的是 beyes_dir 目录上的默认规则权限,而非自身的用户组权限。可以用下面的实验来证明这一点:[beyes@groad.net tmp]$ rm -rf beyes_dir/
[beyes@groad.net tmp]$ mkdir beyes_dir
[beyes@groad.net tmp]$ chmod g-rx beyes_dir/
[beyes@groad.net tmp]$ setfacl -m d:u:sky:rwx,u:sky:rwx beyes_dir/
[beyes@groad.net tmp]$ getfacl beyes_dir/
# file: beyes_dir/
# owner: beyes
# group: beyes
user::rwx
user:sky:rwx
group::-w-
mask::rwx
other::r-x
default:user::rwx
default:user:sky:rwx
default:group::-w-
default:mask::rwx
default:other::r-x
[beyes@groad.net tmp]$ touch beyes_dir/1.txt
[beyes@groad.net tmp]$ getfacl beyes_dir/1.txt
# file: beyes_dir/1.txt
# owner: beyes
# group: beyes
user::rw-
user:sky:rwx #effective:rw-
group::-w-
mask::rw-
other::r-- 为什么要这么继承?可以想象,sky 这个人来被安排到别的部门工作,自然要按照那个部门的规矩来做事。
至于 other ,它也继承自文件传统权限中的 other ,因此这里是 other::r-- 。
下面来测试一种可删除,但不能写的情况。
首先为 beyes_dir 这个目录再添加一条默认规则:[beyes@groad.net tmp]$ rm -rf beyes_dir/
[beyes@groad.net tmp]$ mkdir beyes_dir
[beyes@groad.net tmp]$ setfacl -m d:g:corp:rwx,g:corp:rwx beyes_dir/
[beyes@groad.net tmp]$ getfacl beyes_dir/
# file: beyes_dir/
# owner: beyes
# group: beyes
user::rwx
group::rwx
group:corp:rwx
mask::rwx
other::r-x
default:user::rwx
default:group::rwx
default:group:corp:rwx
default:mask::rwx
default:other::r-x
使用 sky (用户组为 corp) 这个用户在 beyes_dir 中添加 1 个文件,并更改其权限:[sky@groad.net beyes_dir]$ chmod 000 1.txt
[sky@groad.net beyes_dir]$ ll 1.txt
----------+ 1 sky corp 0 Mar 11 13:16 1.txt
[sky@groad.net beyes_dir]$ getfacl 1.txt
# file: 1.txt
# owner: sky
# group: corp
user::---
group::rwx #effective:---
group:corp:rwx #effective:---
mask::---
other::--- 使用另外一个属于 corp 组的用户 gilble 来写 1.txt 这个文件:
[qutoe][gilble@groad.net beyes_dir]$ echo "hello world" > 1.txt
-bash: 1.txt: Permission denied[/quote]
是的,确实没法写。但是能删除不?然而,它却可以被删除。这种情况令人有点费解,但它就是这样子。由此可见,不管默认规则如何设置,只要在真正添加权限时,被实际添加的权限优先于默认规则权限。如实际添加权限具有可写的权限,即使面对一个看上去没有任何权限的文件,在最极端的情况下还是可以被删除的。 |
|