I would like to override the default umask and owner:group settings within certain directories only, without requiring root privileges, as that kind of defeats the purpose.

For example, when I touch a file in /var/www/ it becomes 0755 and owned by redsandro:redsandro.

I would like this to default to 0770 and redsandro:www-data for everything within /var/www/.

Maybe there's a better solution for this specific scenario. This seemed to be the only way to have both my non-root user and the webserver in full control over /var/www/. As the only user of this machine, I like the htdocs to be 'mine' without being root. Apache becomes fed up though when you take too much territory inside htdocs.

Here is a related question for the umask part where the answer is "no". But I am sure others have sought the same functionality, and I can imagine pwd based umask is available somehow just like git uses .git to store pwd independent settings that go up the directory-tree. Or down, I'm not sure if you call subdirectories up or down the tree. ;)


Partial answer:

Add the setgid bit on the parent directory:

sudo chown redsandro:www-data /var/www
sudo chmod 2770 /var/www


sudo chmod u=rwx,g=rwxs /var/www

Since you desire both user and group set this should work.

sudo chown -R redsandro:www-data /var/www

To change ownership.

Then do:

sudo u=rwx, g=rwxs /var/www

To keep that ownership change above permanent.

  • Setuid on directories has no effect. – muru Nov 30 '16 at 6:45
  • @muru please I would need an explanation on this as I have done this with a folder on mu Ubuntu Xenial here is the result of stat -c %A www, drwsrwsr-x. Still any info will appraciated – George Udosen Nov 30 '16 at 7:08
  • you'll see the setuid bit in the output, you won't see any effect of it. – muru Nov 30 '16 at 7:12

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.