16
$ whoami
meder
$ 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?

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

2 Answers 2

31

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.

3
  • what's g+s in numbers? Commented Jul 23, 2013 at 6:39
  • 1
    @WearetheWorld prepend with 2: chmod 2XXX file.
    – makes
    Commented Jul 23, 2013 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
    Commented Jul 27, 2014 at 19:27
0

You need to set the setgid bit on the directory.

chmod g+s html
3
  • Can I combine this chmod with the g+rwx one? Commented Jan 6, 2011 at 19:47
  • 1
    @meder: yes g+rwxs Commented Jan 6, 2011 at 19:54
  • This only preserves directory ownership, not directory permissions.
    – Glyph
    Commented Jul 27, 2014 at 19:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .