$ whoami
$ cd /var/www
$ sudo mkdir html
$ sudo groupadd web
$ sudo usermod -a -G web meder
$ sudo usermod -a -G web medertest
$ sudo chown meder:web html
$ sudo chmod -R g+rwx html

The problem is, anytime I create a new file in /var/www/html even though the group is set to web, it is only writeable by the original user.

I was given the advice of setting the umask to be 002 because the default is what causes the problems. But I would have to do this for all users in that group, and as far as I know it would be tedious having all of them modify ~/.bashrc to have umask 002. Even if I can do it myself with a shell command for all of those users, it still seems too tedious.

Can anyone offer any advice on having a group writeable directory?

  • 2
    Have you tried logging out and then logging again with the user meder? Group information is not updated in the current session. – marco Jan 6 '11 at 18:52
  • @marco - I did su medertest and su meder like a thousand times. Does that qualify as a log out? – meder omuraliev Jan 6 '11 at 19:12
  • @marco thanks did not know that group info is not updated in the current session... bummer – gabeio Apr 23 '15 at 0:43

First, enable the SGID bit on your directory:

sudo chmod g+s html

This will make new files created inside that directory inherit the parent's group ownership.

There is no inheritance of permission levels in the POSIX permission model. However, this can be done with Access Control Lists, without having to worry about umask settings:

sudo setfacl -d -m group:web:rwx html

It's a real bummer that umask cannot be assigned on a per-directory basis.

  • what's g+s in numbers? – Jürgen Paul Jul 23 '13 at 6:39
  • 1
    @WearetheWorld prepend with 2: chmod 2XXX file. – mizo Jul 23 '13 at 11:46
  • 1
    I have been hunting around for this answer forever, and I just got referred to it via a Twitter response. Thanks @mizo! – Glyph Jul 27 '14 at 19:27

You need to set the setgid bit on the directory.

chmod g+s html
  • Can I combine this chmod with the g+rwx one? – meder omuraliev Jan 6 '11 at 19:47
  • 1
    @meder: yes g+rwxs – Paused until further notice. Jan 6 '11 at 19:54
  • This only preserves directory ownership, not directory permissions. – Glyph Jul 27 '14 at 19:26

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.