I have an annoying problem. I have made a user account that I want to be able to create files and folders off a chroot'd directory /home/user/. So it can do what it wants there. But I want the default permissions of newly created files to be 660, and newly created directories to be 770 (since the owner and group need the execute bit set to change down into that folder).

I can't find a method to actually accomplish this, since setfacl or umask both appear to affect files and folders.

People keep telling the answer is to use umask 0007. However I disagree, because the mask would allow rwx for all new files and folder created by user or group. If the application allows to create a file with the x bit set, then the mask would also allow the file to inherit that setting.

  • That's exactly how umask should work (since it's a mask) - try for example umask 0007; mkdir foo; touch bar – steeldriver Jun 4 '18 at 13:25
  • If I use umark 0077, that would make all my files also 770, which is not what I want. – john smith Jun 4 '18 at 14:48
  • 1
    That should not be the case: umask 0077; mkdir foo; touch bar; stat -c %a foo bar ==> 700 600 – steeldriver Jun 4 '18 at 15:36
  • Yes but that's just masking a setting created by touch. Touch creates the file without the x bit set, then linux runs the file through umask, which says ok that 600 setting is allowed, and retain the settings. This means I could maliciously create a program that sets rwx bits on group/user filers and gain execute permissions on my file. – john smith Jun 5 '18 at 4:28
  • Umask is applied by the open(2) system call, not by touch or other commands. So I don't understand what you mean by "setting created by touch" and "linux ... retain[s] the settings". – muru Jun 5 '18 at 4:39

Your Answer

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

Browse other questions tagged or ask your own question.