I am running Ubuntu 16.04.

I have several users that are within the www-data group and will be creating/modifying files on the server.

We'll call them user1 and user2.

Any time user1 or user2 creates a folder or file within /var/www/sites/domain1.com/public I would like the owner and group to default to www-data. I would like the files to have the permissions of 0664 and the folders to have the permissions of 0775.

So lets say user1 is logged in and creates a file called test-file.txt

If I run:

ls -l on /var/www/sites/domain1.com/public

I would like the output to look like:

-rw-rw-r-- www-data www-data test-file.txt

I believe this can be done with setfacl, but am not quite sure what the command would be or if there is a better way.


1 Answer 1


Changing the directory permissions from 0775 to 2775 would give you most of what you ask for. The 2 means set group ID and when used on a directory means that new objects created within that directory will inherit the group of the directory rather than getting the current group of the process which created the object.

If the directories are not already owned by group www-data you need to change the group first before changing permissions.

Additionally you need to ensure that the umask of each user is 0002. that is the default so unless the users have changed it will already have the correct value.

Doing the above covers everything you asked for except from changing the owner of the files. I haven't come across usage scenarios where that difference was important, and having the owner of a file indicate who created the file can be useful.

A completely different approach would be to use a source control system and create a procedure for pushing updates of the files from source control. Using source control is a major help when multiple people need to update the same files.

  • I ran a sudo chmod 2755 -R /var/www/sites/domain1.com/public, but that now doesn't let me add files/folders unless I use the sudo command. Was there a different way I should be doing this? Plus I wanted only folders to have 775 and files to have 664. Thanks Dec 28, 2017 at 17:05
  • @bigmike7801 I said 2775 not 2755. Also I only said to change it on directories not files. The files should remain 0664.
    – kasperd
    Dec 28, 2017 at 17:06
  • sorry I fat-fingered the "2775". Dec 28, 2017 at 17:13
  • @bigmike7801 Did you ensure the directories had correct group before using chmod?
    – kasperd
    Dec 28, 2017 at 17:16
  • 1
    @bigmike7801 Notice they are called directories and not "folders", a Windows-ism.
    – Rob
    Dec 28, 2017 at 17:50

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.