In Linux when I create a directory mkdir newdir then the newly created directory has these permissions and ownership: drwxr-xr-x 2 owner group

My Question

How can I make the default permissions for newly created DIRECTORIES be: drwxrwxrwx 2 owner group regardless of who created the directory?

Some research I made

I know that from within a Samba share you can enforce that with directory mask but what if someone goes to the terminal and makes a directory as root and then a regular user comes along and he then won't be able to create files in that directory that the root user made?

I have been playing with ACLs and I understand how to make all newly created FILES have certain permissions.

e.g: setfacl -dRm u::rwX,g::rwX,o::0 newdir/

This makes all files in the newdir folder have permission: -rw-rw---- regardless of who created the file.

I also learnt about "setting the directory group id bit" so that any files (or directories) created in the "newdir" directory will have group ownership equal to the group ownership of the "newdir" directory. chmod g+s newdir/

I have not been able to find out how to make the default permissions for a newly created DIRECTORY be: drwxrwxrwx 2 owner group regardless of who ever created the directory? Maybe it's something to do with umask? Can it be done with ACLs?

  • Maybe the question is closed to new answers? I have found another way to enforce creation of directories with drwxrwxrwx permissions. Applying the ACL rule: setfacl -dRm u::rwx,g::rwx,o::rwx testDir/ will make all newly created directories and sub directories in testDir have permission: drwxrwxrwx+ and all newly created files in testDir will have permission -rw-rw-rw- Newly created files are not given the execute bit by design of Unix/Linux. – FlexMcMurphy Mar 3 at 0:25

Yes you are correct - the default permissions are determined by the umask of the creating process. Unfortunately (unlike the SAMBA mount options, which provide separate dmask and fmask), the shell's umask applies to both directories and files:

$ umask 0000
$ mkdir newdir ; touch newfile
$ ls -ld new{dir,file}
drwxrwxrwx 1 steeldriver steeldriver 512 Mar  2 17:22 newdir
-rw-rw-rw- 1 steeldriver steeldriver   0 Mar  2 17:22 newfile

In any case, you can't control the umask of other user's processes (especially not root's).

  • Cheers. On my system I see that I would edit the file /etc/login.defs to set the umask system wide which I suppose would affect root also. Do you happen to know if this can be done with ACLs? Or do they only apply to files? – FlexMcMurphy Mar 2 at 22:55
  • @FlexMcMurphy tbh I couldn't answer either question confidently; I think that the default umask is now set via the pam_umask module so there may be other factors than just the login.defs file. In any case, users can change their own umask via the shell (as my example shows). – steeldriver Mar 2 at 23:03

Check the manual (man mkdir):

-m, --mode=MODE
    set file mode (as in chmod), not a=rwx - umask

So you just need to:

mkdir -m 777 newdir
  • OK but can I make the permissions be drwxrwxrwx when I just type mkdir newdir ? Basically I am trying to avoid the situation where someone, maybe root, can make a directory that other users can then not be able to write to. I have a Samba file share and I need it to be wide open. I'm concerned that directories might get made from Terminal and not just from when connected to the Share. – FlexMcMurphy Mar 2 at 22:09
  • @FlexMcMurphy, ok I understood... using an alias may be the solution, but it all depends on who can access the system to create directories. – schrodigerscatcuriosity Mar 2 at 22:29
  • 1
    @FlexMcMurphy it seems that the link provided by vanadium in his comment is the best solution. – schrodigerscatcuriosity Mar 2 at 22:31

Not the most efficent idea but it gets the job done. Make a cronjob run by root its one job is to execute the command /usr/bin/chmod -R 0777 /path/to/samba/share. Problem is solved at the interval chosen by you every time it runs that job.

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