I'd like for the ownership of all the files on my site to stay as follows:

sudo chown -R www-data:www-data /var/www/example.com/public_html

But I need to change the files with another user, so I did the following to set ACLs:

setfacl -Rdm u:sampleuser:rwx /var/www/example.com/public_html

But now, if I upload a new file, that file is owned by sampleuser, not www-data.

Is there any way to keep it as www-data for all files/directories even after I add new files with sampleuser?

I'm running Ubuntu 18.04.

  • Generally, a file will be owned by its creator. In the case of a web application, the creator is usually the web application itself. Here, it sounds like you're uploading a new file with a different user account, so that's what will own the file. – roaima May 7 at 11:17

You could enforce the group to always be www-data by setting the sampleuser to that group.

sudo usermod -a -g www-data sampleuser

Now set the default group permissions on any files folders created within:

setfacl -m "default:group::rwx" /var/www/example.com/public_html

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.