[root@FC3-vm opt]# cd /mnt
[root@FC3-vm mnt]# ls
lost+found
现在我已经得到了一个小型的文件系统。而且是支持 ACL 的。并且即使彻底损坏也不会影响
硬盘上其他有价值的数据。可以开始我们的 ACL 体验之旅了。
 回页首
体验 1 - ACL 的基本操作:添加和修改
我首先新建一个文件作为实施 ACL 的对象:
[root@FC3-vm mnt]# touch file1
[root@FC3-vm mnt]# ls -l file1
-rw-r--r-- 1 root root 7 Dec 11 00:28 file1
然后看一下这个文件缺省的 ACL,这时这个文件除了通常的 UGO 的权限之外,并没有 ACL:
[root@FC3-vm mnt]# getfacl file1
# file: file1
# owner: root
# group: root
user::rw-
group::r--
other::r-
*注意:即使是不支持 ACL 的情况下,getfacl 仍然能返回一个这样的结果。不过 setfacl 是
不能工作的。
下面添加几个用户和组,一会我将使用 ACL 赋予他们不同的权限:
[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
修改成功了,用户 testu1 可以对 file1 做读写操作了。我们来看一下 file1 的 ACL:
[testu1@FC3-vm mnt]$ getfacl file1
# file: file1
# owner: root
# group: root
user::rw-
user:testu1:rw-