FedoraCore3上的ACL实验

王朝other·作者佚名  2008-05-18
窄屏简体版  字體: |||超大  

这周拿到了FC3(感谢ChinaUnix和里仁),就安装了一下。一直想实验一下ACL,正好FC3是2.6.9的kernel。开始实验吧。

简介

先 来简单介绍一下ACL吧。大家对Linux/Unix的UGO权限管理方式一定不陌生,还有最常用的chmod命令。为了实现一些比较复杂的权限管理,往 往不得不创建很多的组,并加以详细的记录和区分(真是管理员的恶梦)。要是可以针对某一个用户对某一文件指定一个权限,那有多好啊。比如张三可以读取,李 四所在的组可以写,但是李四不可以……,功能强大啊。于是就有了IEEE POSIX 1003.1e这个ACL的标准。所谓ACL,就是Access Control List,也就是一个文件/目录的访问控制列表,可以针对任意指定的用户/组分配RWX权限。现在主流的商业Unix系统都支持ACL(不知道SCO是不 是支持)。FreeBSD也是支持的。Linux从2.6开始也是支持ACL了。

实验准备

支 持ACL需要内核和文件系统的支持。现在EXT2/EXT3, JFS, XFS, ReiserFS都是可以支持ACL的。可是总不能拿自己的分区做实验吧。万一玩坏了就惨了。还是作一个loop设备好了。这样不需要一个单独的分区,也 不需要很大的空间,大约有个几百KB就够了。我下面就用Fedora Core 3和EXT2文件系统做实验。

首先创建一个512KB的空白文件:

[root@FC3-vm opt]# dd if=/dev/zero of=/opt/testptn count=512

512+0 records in

512+0 records out

和一个loop设备联系在一起:

[root@FC3-vm opt]# losetup /dev/loop0 /opt/testptn

创建一个EXT2的文件系统:

[root@FC3-vm opt]# mke2fs /dev/loop0

mke2fs 1.35 (28-Feb-2004)

max_blocks 262144, rsv_groups = 32, rsv_gdb = 0

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

32 inodes, 256 blocks

12 blocks (4.69%) reserved for the super user

First data block=1

1 block group

8192 blocks per group, 8192 fragments per group

32 inodes per group

Writing inode tables: done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

把新建的文件系统mount上(注意mount选项里的acl):

[root@FC3-vm opt]# mount -o rw,acl /dev/loop0 /mnt

[root@FC3-vm opt]# cd /mnt

[root@FC3-vm mnt]# ls

lost+found

现在我们已经看到了一个小型的文件系统。而且是支持ACL的。可以开始实验了。

实验

现在开始实验,首先新建一个文件:

[root@FC3-vm mnt]# touch file1

然后看一下缺省的FACL,这时这个文件除了通常的UGO的权限之外,并没有ACL:

[root@FC3-vm mnt]# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

group::r--

other::r--

注意:即使是不支持ACL的情况下,getfacl仍然能返回一个这样的结果。不过setfacl是不能工作的。

开始正式实验,首先添加几个用户和组:

[root@FC3-vm mnt]# groupadd testg1

[root@FC3-vm mnt]# useradd testu1

[root@FC3-vm mnt]# useradd testu2

[root@FC3-vm mnt]# usermod -G testg1 testu1

现在我们看看testu1能做什么:

[root@FC3-vm mnt]# su testu1

[testu1@FC3-vm mnt]$ echo "testu1" >> file1

bash: file1: Permission denied

失败了。因为file1并不允许除了root以外的用户写。我们现在就通过修改file1的ACL赋予testu1足够的权限:

[root@FC3-vm mnt]# setfacl -m u:testu1:rw file1

[root@FC3-vm mnt]# su testu1

[testu1@FC3-vm mnt]$ echo "testu1" >> file1

[testu1@FC3-vm mnt]$ cat file1

testu1

修改成功了。我们来看一下file1的ACL:

[testu1@FC3-vm mnt]$ getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rw-

group::r--

mask::rw-

other::r--

资源

Linux ACL的主页: http://acl.bestbits.at/

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航