I know how to use setgid on directories, to enforce that whole directory structure has uniform user:group ownership.

Is there a similar way to set the umask for a directory, so that the whole directory structure "inherits" specific permissions (i.e. 750/640)?

  • 2
    No, umasks aren't attached to directories, they're attached to a process. askubuntu.com/questions/44534/…. Setting a ACL (using setfacl) might be a way though. – slm Jan 28 '14 at 14:34

Here is ugly hack to apply on directory.

mount -o loop,umask=027,uid=test /opt/dev_test /home/test/test2

Since umask on mount point applied on NTFS or VFAT partition, I had created block device using dd command then formatted with mkfs.vfat and mounted with command as mentioned above.

Test Result

Inside test2 directory

[test@test-server test2]$ touch xyz
[test@test-server test2]$ ls -rlt xyz
-rwxr-x--- 1 test root 0 Jan 28 23:22 xyz
[test@test-server test2]$ umask

Outside test2 directory

[test@test-server test2]$ cd ../
[test@test-server ~]$ touch xyz
[test@test-server ~]$ ls -rlt xyz
-rw-rw-r-- 1 test test 0 Jan 28 23:22 xyz
[test@test-server ~]$ umask

The umask value for the process that creates a file or a directory will control the ultimate specific permissions at the time the process executes. By convention (default), files are created with a creation mode (to open()) of 0666 while directories are created with 0777. The umask value is then factored in to establish the final permissions.

Thus, your "best" choice is to make sure that processes that manipulate the particular directory use a umask of 0027 while will provide directories with 0750 and files with 0640.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.