Shared directories

Sometimes you need a couple of users to share a directory, for example a number of developers who test in their own directory but deploy to a central directory. As an example, we'll take the /var/www directory, which we assume is already present on the system.

First create a common group:

  # groupadd wwwdev

Then add all users to this group:

  # usermod -a -G wwwdev user1
  # usermod -a -G wwwdev user2
  ... et cetera

Change the group of the directory and do the same for all underlying files and directories:

  # chgrp -R wwwdev /var/www

Find the directory and all subdirectories. Set the setgid bit on the directory (which makes sure that new files are owned by the group), and also make sure the directory is readable, writeable and accessible:

  # find /var/www -type d -exec chmod g+srwx {} \;

At this point, all directories can be written to by everyone in the group. Now make all files writeble as well.

  # chmod -R g+w /var/www

To let users easily edit each others documents, it's best they set the umask to 002 instead of the usually default 022. In the shell initialization file (for instance .bashrc), add the line

  umask 002

Tip: if users encounter a file where the group does not have write permission, it's easily fixed by the individual user copying the other user its file, deleting the original and renaming the copy back to the original name.

There is no way to set a property on the directory forcing newly created files to have the group write bit.

Setting the umask in .bashrc will not affect the way that directories and files are created in desktop environments. This is outlined below.


Under Debian and Ubuntu, you can create a file called $HOME/.gnomerc and add the line

  umask 002

I have not tested this under other distributions.


Under Debian and Ubuntu, you can create a directory called $HOME/.kde/env and add files there. Name the file for example "" and add one line:

  umask 002

I have not tested this under other distributions.