I am working on a desktop environment with Ubuntu 18.04.

I have my Apache 2 server setup with multiple websites in the folder /var/www/ (each site lives in its own folder there)

Made myself owner and assigned www-data as group : sudo chown $USER:www-data -R /var/www

Fixed permissions with : sudo chmod -R 774 /var/www

Everything works fine, untill I add a file or add a new website (git pull). New files will not come with the group www-data. Disallowing Apache to run.

This is fixed by re executing sudo chmod -R 774 /var/www, but this doesn't feel like a fix.

What do I do wrong?

Edit: It seems git pull doesn't respect the permissions I have set earlier. Even though the parent folder has the permissions set correctly.

  • 1
    Google "setgid bit".
    – fkraiem
    May 1, 2019 at 11:56
  • @fkraiem Would you mind explaining a little more?
    – mike
    May 1, 2019 at 12:07

1 Answer 1


You need to set setgid bit for all folders:

chown $USER:www-data -R /var/www    
chmod -R g+s /var/www

Then every new file created in "setgid folder" will have group of parent folder. User who do create file must be in www-data group

WWW files permissions can be limited to your user(read-write) and www-data group(only read), while others don't have any persissions:

chmod -R u=rwX,g=rs,o= /var/www
  • Will this mean I can't create files anymore under my own user? (without being in the group www-data)
    – mike
    May 1, 2019 at 12:56
  • Just add your user to www-data, and create any file will be fine. Created files will have incorrect group if user not in group.
    – LeonidMew
    May 1, 2019 at 12:58

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.