Creating a shared directory under Linux

When two users on Linux need to share files, accession rights can be quite a problem. By default only the one who creates the file can read and modify it, even if it is saved in a directory that is accessible by the other. It appears to me still impossible to solve this problem completely as Linux cannot "inherit" privileges to newly creates/saved files based on their parent directories privileges (BTW: how has Mac OS X solved this problem?)

The following instructions create a shared directory, but require additional tweaks.
As root

  1. Create a unix group and make the users members of that group
  2. Create the directory (if it doesn't exist already)
  3. Set all files and directories in that directory to belong to that group (the -R is recursive): "chgrp -R group path"
  4. Set directory permissions for the newly created directory: "chmod 770 path" and "chmod g+s path" ("chmod 775 path" to allow read (but not write) access to everybody
  5. Then if you already have files in that directory you can set the rest of the file and directory permissions as follows: "chmod -R a+rX,ug+w"
  6. Set the `SGID' flag for directories (WARNING: do NOT do this for files where the SGID flag has a very different meaning!!!): find dir -type d -print | xargs chmod g+s

The remaining problem is that whenever you create a new file or directory you would have to set the umask to 002 ("umask 002"). This temporarily changes the default umask and files created thereafter will be both readable and writable by the group.

For files: 002 -rw-rw-r-- user can read and write file; group can read and write; others can read For directories: 002 drwxrwxr-x user can read, write, list names of files in the directory, and delete files from the directory; group can do the same as the user; others can read and list names of files)

Using the umask is not very handy. A workaround is to execute the chmod command automatically via crontab in regular intervals or after logout (if the files are only accessed from one workstation).