如何在文件/文件夹权限中添加点递归

如何在文件/文件夹权限中添加点递归

具有权限的文件示例

-rwxr-xr-x. 1 root root  659 Jan  4  2018 zookeeper-server-initialize
-rwxr-xr-x. 1 root root  649 Jan  4  2018 zookeeper-server-cleanup
-rwxr-xr-x. 1 root root  648 Jan  4  2018 zookeeper-server
-rwxr-xr-x. 1 root root  303 Jan  4  2018 zookeeper-client
-rwxr-xr-x. 1 root root 6822 Jan  4  2018 zkServer.sh
-rwxr-xr-x. 1 root root   12 Jan  4  2018 zkServer-initialize.sh
-rwxr-xr-x. 1 root root 2840 Jan  4  2018 zkEnv.sh
-rwxr-xr-x. 1 root root 1709 Jan  4  2018 zkCli.sh
-rwxr-xr-x. 1 root root 2155 Jan  4  2018 zkCleanup.sh

如果我们只有这个文件,例如:(没有点)

-rwxr-xr-x 1 root root 2155 Jan  4  2018 zkCleanup.sh

那么,将这个点添加到文件权限的命令是什么?

第二如何添加点递归

例如在以下所有子文件夹中

/usr/hdp/current/zookeeper-server

之前的例子

 pwd
/usr/hdp/current/zookeeper-server


 ls -Z
drwxr-xr-x root root ?                                bin
lrwxrwxrwx root root ?                                conf -> /etc/zookeeper/2.6.4.0-91/0
drwxr-xr-x root root ?                                doc
drwxr-xr-x root root ?                                etc
drwxr-xr-x root root ?                                lib
drwxr-xr-x root root ?                                man
drwxr-xr-x root root ?                                usr
-rw-r--r-- root root ?                                zookeeper-3.4.6.2.6.4.0-91.jar
lrwxrwxrwx root root ?                                zookeeper.jar -> zookeeper-3.4.6.2.6.4.0-91.jar

预期输出:

 pwd
/usr/hdp/current/zookeeper-server

ls -Z
drwxr-xr-x. root root system_u:object_r:bin_t:s0       bin
lrwxrwxrwx. root root unconfined_u:object_r:usr_t:s0   conf -> /etc/zookeeper/2.6.4.0-91/0
drwxr-xr-x. root root system_u:object_r:usr_t:s0       doc
drwxr-xr-x. root root system_u:object_r:usr_t:s0       etc
drwxr-xr-x. root root system_u:object_r:lib_t:s0       lib
drwxr-xr-x. root root system_u:object_r:usr_t:s0       man
drwxr-xr-x. root root system_u:object_r:usr_t:s0       usr
-rw-r--r--. root root system_u:object_r:usr_t:s0       zookeeper-3.4.6.2.6.4.0-91.jar
lrwxrwxrwx. root root system_u:object_r:usr_t:s0       zookeeper.jar -> zookeeper-3.4.6.2.6.4.0-91.jar

我们尝试

restorecon -r /usr/hdp
ls -ltr
total 12
drwxr-xr-x. 27 root root 4096 Oct 29 10:05 2.6.0.3-8
drwxr-xr-x  29 root root 4096 Nov  6 11:29 2.6.4.0-91
drwxr-xr-x.  2 root root 4096 Dec 31 13:01 current

但 2.6.4.0-91 文件夹具有相同的权限(包括 2.6.4.0-91 下的子文件夹)

ls -Z
drwxr-xr-x. root root system_u:object_r:usr_t:s0       2.6.0.3-8
drwxr-xr-x  root root ?                                2.6.4.0-91
drwxr-xr-x. root root unconfined_u:object_r:usr_t:s0   current

答案1

尾随.表示文件具有 SElinux 安全上下文。要设置默认安全上下文,您应该能够运行

restorecon -r /usr/hdp 

以上要求您在系统上启用 SELinux。如果没有,则必须启用它并标记文件系统

编辑 /etc/selinux/config 并确保

SELINUX=enforcing # or permissive
SELINUXTYPW=targeted

然后运行命令

touch /.autorelabel
reboot

相关内容