0

I created a directory, which is owned by the www-data group. I would like to make the files in it writeable by the members of the group, no matter who created the file. My username is pi. I tried it like this:

mkdir ./shared
sudo chown pi ./shared
sudo chgrp www-data ./shared
sudo chmod -R 770 ./shared
sudo chmod g+sw ./shared

If I check it with ls -l, it looks like this:

drwxrws--- 2 pi   www-data 4096 sept 28 17:10  shared

I created a new file in it:

cd ./shared
touch ./test.txt

But if I check, the group has no write right for the new test.txt

-rw-r--r-- 1 pi www-data 0 sept 28 17:10 test.txt

What do I wrong? I can not run sudo chmod -R 770 ./shared each time, a new file is created in the directory by a script/webserver.

How is it possible to create a shared directory, where both the owner and the group members have read and write rights for the files, regardless who created a specific file?

2
  • What is the value of your umask? – spuck Sep 28 '20 at 15:35
  • Even if I set my umask to 002, calling sudo -u www-data touch ./foo.txt creates a file, which is not group-writeable – Iter Ator Sep 28 '20 at 16:05
0

If the system and file-system supports posix-draft-type ACLs, you can do:

setfacl -m d:g::rw ./shared

For newly created files in there to be automatically given read+write permission to the group, even if the umask of the processes creating those files would normally not grant those permissions.

In any case, that doesn't stop users from removing those permissions with chmod/setfacl afterwards.

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.