Linux上的ACL权限文件访问
在 unix/linux 系统上沿用了多年的权限机制,由于欠缺灵活性,在现今的信息系统上显得落后和不敷应用。然而一个新的权限机制标准已经诞生出来,本
文将会为大家介绍这个新机制在 linux 上的操作方式。
---------------------------------------------------------
典型的文件权限
典型的文件权限是这样的:
#>ls -l
-rwxrw-r-- 1 adam mis 272401 may 10 2003 test.doc
表示文件属于用户adam,权限可读可写可运行;属于群组mis权限可读可写;其他人权限只读
传统的权限只能对所有者,群组,其他来设定3套权限
更复杂的权限则需要依赖acl
这个 posix acl 的功能在 linux kernel 2.6 上被正式支持,之后又被 back-port到 2.4 kernel 上。大家常用的档案系统,如:ext3,xfs,jfs,和
reiserfs,都能使用acl。当然,大家须要在编译 kernel 时启动 acl。
---------------------------------------------------------
启动 acl
虽然在 kernel 中已加进了 posix acl 的支持,但是并不会自动启用的。我们必须在挂上档案系统时指明要使用 acl。例如:
mount -t ext3 -o acl /dev/sda1 /home
其中 “-o acl”参数表示在 /dev/sda1 上启用 acl 的选项。我们亦可以在 /etc/fstab 中加入选项:
/dev/sda1 /home ext3 acl 1 2
---------------------------------------------------------
查看文件的acl信息
#>getfacl test.doc
# file: test.doc
# owner: adam
# group: mis
user::rw-
group::rw-
other::r--
---------------------------------------------------------
访问型acl设置[www.iocblog.net 来源]
更改acl
setfacl” 指令能更改一个档案或目录的 acl。其用法如下:
setfacl option rules files
option:
-m 用来新增或修改 acl 中的规则
-x 用来移除 acl 中的规则[www.iocblog.net 来源]
rules:
user:(uid/name):(perms) 指定某位使用者的权限
group:(gid/name):(perms) 指定某一群组的权限
other::(perms) 指定其它使用者的权限
mask::(perms) 设定有效的权限屏蔽
如果想让hr群组的使用者能读取 “test.doc”而其它的人不能读取的话。 我们可以用以下的指令达成:
setfacl -m group:hr:r,other::- test.doc
以 getfacl 检视新的 acl:
[adam@www adam]$ getfacl test.doc
# file: test.doc
# owner: adam
# group: mis
user::rw-
group::rw-
group:hr:r--
mask::rw-
other::---
要让使用者 adam 和 eva 能 读取 和 写入, 群组mis 和 hr 只能读取, 其它人不能 读取 和 写入。 我们只须多加两个规则便能达成: