2

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.

bigmike7801
  • 131
  • 4
  • https://www.google.com/amp/s/odd.blog/2013/11/05/fix-file-644-directory-775-permissions-linux-easily/amp/ will help you – Jacob Evans Dec 29 '17 at 04:51

1 Answers1

2

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.

kasperd
  • 29,894
  • 16
  • 72
  • 122