How to configure permissions recursively, 700 for folders and 600 for files, without using find

I am trying to figure out a way to recursively set permissions for dirs and subdirs on a specific path and 600 for files. I would use the following commands:

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

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 create a script that contains the above commands from the root user with the setuid bit set, so it will run with root privileges (such as passwd or sudo commands that ordinary users run with root privileges):

chmod 4755 script.sh

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

Does anyone know how I can do this without using the find command?

Edit: OS: Centos 6.5

+5
source share
1 answer

This seems to be very easy to implement. There are two ways: use only chmod or set an ACL (access control list) along the desired path:

  • Using chmod I will start:

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

for the owner of the user, I give the capital "X", so it applies only to directories, not files.

  • Using ACL:

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

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

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

+6
source

Source: https://habr.com/ru/post/1246880/


All Articles