在linux 系统中,可以通过setfacl 来实现目录下创建文件或子目录,并继承父目录的权限。
下面以 root 用普通用户 user1 .在目录/mnt下
[[email protected] mnt]# setfacl -m u:user1:rwx share //为目录添加ower = user1 ,并赋予rwx 的权根。 [[email protected] mnt]# setfacl -d -m u:user1:rwx share //为目录添加默认的acl权限,此目录下创建目录和文件都会继承此权限信息 [[email protected] mnt]# [[email protected] mnt]# [[email protected] mnt]# getfacl share //查看share的facl信息 # file: share # owner: root # group: root user::rwx user:user1:rwx // 此时user1才能对share有写权限 group::r-x mask::rwx other::r-x default:user::rwx //默认子目录或文件的权限信息 default:user:user1:rwx default:group::r-x default:mask::rwx default:other::r-x [[email protected] mnt]# cd share/ [[email protected] share]# ls [[email protected] share]# touch roota [[email protected] share]# touch rootb [[email protected] share]# mkdir rootdir1 [[email protected] share]# mkdir rootdir2 [[email protected] share]# ls roota rootb rootdir1 rootdir2 [[email protected] share]# getfacl roota # file: roota # owner: root # group: root user::rw- user:user1:rwx #effective:rw- group::r-x #effective:r-- mask::rw- other::r-- [[email protected] share]# getfacl rootdira getfacl: rootdira: No such file or directory [[email protected] share]# getfacl rootdir rootdir1/ rootdir2/ [[email protected] share]# getfacl rootdir1 # file: rootdir1 # owner: root # group: root user::rwx user:user1:rwx group::r-x mask::rwx other::r-x default:user::rwx default:user:user1:rwx default:group::r-x default:mask::rwx default:other::r-x [[email protected] share]# 现在用user1 进入此目录来检测权限:
[[email protected] share]$
[[email protected] share]$
[[email protected] share]$
[[email protected] share]$ ll
total 8
-rw-rw-r--+ 1 root root 0 Nov 19 22:52 roota
-rw-rw-r--+ 1 root root 0 Nov 19 22:52 rootb
drwxrwxr-x+ 2 root root 6 Nov 19 22:52 rootdir1
drwxrwxr-x+ 2 root root 6 Nov 19 22:52 rootdir2
[[email protected] share]$ touch user1a
[[email protected] share]$ touch user1dir1
[[email protected] share]$ getfacl user1a //查看新文件的权限
# file: user1a
# owner: user1
# group: user1
user::rw-
user:user1:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--
[[email protected] share]$ rm roota //尝试删除root创建的文件,成功
[[email protected] share]$ rm rootdir1 //尝试删除root创建的目录,成功
rm: cannot remove arootdir1a: Is a directory
[[email protected] share]$ rm rootdir1 -r
[[email protected] share]$ ll
total 4
-rw-rw-r--+ 1 root root 0 Nov 19 22:52 rootb
drwxrwxr-x+ 2 root root 6 Nov 19 22:52 rootdir2
-rw-rw-r--+ 1 user1 user1 0 Nov 19 22:57 user1a
-rw-rw-r--+ 1 user1 user1 0 Nov 19 22:57 user1dir1
[[email protected] share]$
所以,当有需求要做权根的继承操作时,可以使用这个方来实现。
在新的rhel7 中, 会有新的工具chacl 类似于 setfacl .