Linux shared folders and group permissions How to have a shared folder in Linux that everyone can write into.

Project Description

A combination of simple file permissions and umask settings will allow you to share a folder amongst users, and yet have the folder and its contents owned by a common group. Everyone can read/write/modify, and files aren't owned by any specific user's group.

Project Details

  • Good for webserver html folders
  • Doesn't require any scripts to run
  • Will work with network shared folders
  • Just requires all the users to be added to one common group

Set up the base folder

Create the shared folder somewhere - in my example it's a directory in /var/www that is writable by the webserver and also my own user. It should be owned by the main user and their group, so in my case it's owned by www-data and the group www-data.

Give it 775 permissions (user and group rwx, other r-x) using chmod 775 foldername.

Then apply the setgid bit to the directory using chmod g+s foldername. This is the secret sauce that causes permissions to work correctly. setgid is not the same as the sticky bit. The sticky bit controls who can delete a file, not who owns it.

Add the users to the base group

Now edit /etc/group and make sure the users are all part of the base group. In my case I just need to add my user to the www-data group.

Final notes

If you already have files in the shared folder that need their permissions fixing, a quick chmod 775 * -R and chgrp www-data * -R followed by this to fix the setgid bit should do it:

find /foo -type d -exec chmod g+s {} \;

Replace www-data with whatever group you are using.