ACL权限设置命令setfacl和getfacl命令(7)

如果我们希望在一个目录中新建的文件和目录都使用同一个预定的ACL,那么我们可以使用默认(Default) ACL。在对一个目录设置了默认的ACL以后,每个在目录中创建的文件都会自动继承目录的默认ACL作为自己的ACL。用setfacl的-d选项就可以做到这一点:

[root@FC3-vm mnt]setfacl -d --set g:testg1:rwx dir1 [root@FC3-vm mnt]getfacl dir1filedir1ownerrootgrouproot user::rwx group::r-x other::r-x default:user::rwx default:group::r-x default:group:testg1:rwx default:mask::rwx default:other::r-x

可以看到默认ACL已经被设置了。建立一个文件试试:

 新建一个文件测试 [root@FC3-vm mnt]# touch dir1/file1 [root@FC3-vm mnt]# getfacl dir1/file1 # file: dir1/file1 # owner: root # group: root user::rw- group::r-x                      #effective:r-- group:testg1:rwx                #effective:rw- mask::rw- other::r--

file1自动继承了dir1对testg1设置的ACL。只是由于mask的存在使得testg1只能获得rw-权限。

 5.备份和恢复ACL

主要的文件操作命令cp和mv都支持ACL,只是cp命令需要加上-p 参数。但是tar等常见的备份工具是不会保留目录和文件的ACL信息的。 如果希望备份和恢复带有ACL的文件和目录,那么可以先把ACL备份到一个文件里。以后用--restore选项来回复这个文件中保存的ACL信息:

[root@FC3-vm mnt]getfacl -R dir1 > dir1.acl [root@FC3-vm mnt]ls -l dir1.acl total 16 -rw-r--r--  1 root root   310 Dec 12 21:10 dir1.acl  用-b选项删除所有的ACL数据,来模拟从备份中回复的文件和目录: [root@FC3-vm mnt]# setfacl -R -b dir1 [root@FC3-vm mnt]# getfacl -R dir1 # file: dir1 # owner: root # group: root user::rwx group::r-x other::r-x # file: dir1/file1 # owner: root # group: root user::rw- group::r-- other::r--  现在我们从dir1.acl中恢复被删除的ACL信息: [root@FC3-vm mnt]# setfacl --restore dir1.acl [root@FC3-vm mnt]# getfacl -R dir1 # file: dir1 # owner: root # group: root user::rwx group::r-x other::r-x default:user::rwx default:group::r-x default:group:testg1:rwx default:mask::rwx default:other::r-x # file: dir1/file1 # owner: root # group: root user::rw- group::r-x                      #effective:r-- group:testg1:rwx                #effective:rw- mask::rw- other::r--  6.结语

ACL 的引入使得大规模的复杂权限管理可以很容易的在 Linux 上实现。对于 /home 这样存放大量用户文件的分区,可以做到更有效的管理。但是我们也看到在备份工具等方面的欠缺,好在 FC2 中已经开始包含了 star 这样的支持 ACL 的备份工具,虽然还是 alpha 版。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/11954.html