如何递归设置权限,文件夹为700,文件为600,不使用查找

时间:2021-05-08 16:42:53

I'm trying to figure out a way to set permissions recursively 700 for dirs and subdirs on a specific path and 600 for files. I would use these commands:

我试图找出一种方法来为特定路径上的dirs和subdirs递归设置权限700,为文件设置600。我会使用这些命令:

find /path -type d -print0 | xargs -0 chmod 700

find / path -type d -print0 | xargs -0 chmod 700

find /path -type f -print0 | xargs -0 chmod 600

find / path -type f -print0 | xargs -0 chmod 600

But the user does not have permission to run the "find" command. As a workaround I tried to make a script that contains the above commands from the root user with setuid sticky bit set so it will run with root privileges (like passwd or sudo commands that normal users run with root privileges):

但是用户没有运行“find”命令的权限。作为一种解决方法,我尝试使用setuid粘性位设置从root用户创建包含上述命令的脚本,以便它将以root权限运行(例如普通用户以root权限运行的passwd或sudo命令):

chmod 4755 script.sh

chmod 4755 script.sh

but i cannot execute the script from the limited user account, it still says that I don't have permission to run the find command.

但我无法从有限的用户帐户执行脚本,它仍然说我没有运行find命令的权限。

Does anyone have any idea how i can accomplish this without having to use the "find" command?

有没有人知道如何在不使用“查找”命令的情况下完成此操作?

Edit: OS: Centos 6.5

编辑:操作系统:Centos 6.5

1 个解决方案

#1


6  

Apparently this is very easy to implement. There are 2 ways: using chmod only, or setting ACL (access control list) on the desired path:

显然,这很容易实现。有两种方法:仅使用chmod,或在所需路径上设置ACL(访问控制列表):

  • Using chmod i would run:

    使用chmod我会运行:

    chmod -R u=rwX,g=,o= /path

    chmod -R u = rwX,g =,o = / path

for the user owner i'm giving capital "X", so it does apply only to directories and not files.

对于用户所有者我给大写“X”,所以它只适用于目录而不是文件。

  • Using ACL:

    setfacl -Rm u::rwX,g::0,o::0 /path

    setfacl -Rm u :: rwX,g :: 0,o :: 0 / path

    setfacl -Rm d:u::rwX,g::0,o::0 /path

    setfacl -Rm d:u :: rwX,g :: 0,o :: 0 / path

again using capital "X" so it applies only to directories and not files. The first command applies the ACL, the second one makes it default policy so newly created files will inherit the desired permissions.

再次使用大写“X”,因此它仅适用于目录而不适用于文件。第一个命令应用ACL,第二个命令使其成为默认策略,因此新创建的文件将继承所需的权限。

#1


6  

Apparently this is very easy to implement. There are 2 ways: using chmod only, or setting ACL (access control list) on the desired path:

显然,这很容易实现。有两种方法:仅使用chmod,或在所需路径上设置ACL(访问控制列表):

  • Using chmod i would run:

    使用chmod我会运行:

    chmod -R u=rwX,g=,o= /path

    chmod -R u = rwX,g =,o = / path

for the user owner i'm giving capital "X", so it does apply only to directories and not files.

对于用户所有者我给大写“X”,所以它只适用于目录而不是文件。

  • Using ACL:

    setfacl -Rm u::rwX,g::0,o::0 /path

    setfacl -Rm u :: rwX,g :: 0,o :: 0 / path

    setfacl -Rm d:u::rwX,g::0,o::0 /path

    setfacl -Rm d:u :: rwX,g :: 0,o :: 0 / path

again using capital "X" so it applies only to directories and not files. The first command applies the ACL, the second one makes it default policy so newly created files will inherit the desired permissions.

再次使用大写“X”,因此它仅适用于目录而不适用于文件。第一个命令应用ACL,第二个命令使其成为默认策略,因此新创建的文件将继承所需的权限。