2

What is the best way to share a directory between multiple Linux users? Say I have a directory at /foo (a regular directory no NFS or else) and a bunch of users added to the group bar.

What I want is this behavior:

  1. all users in bar can read/write files and directories in /foo
  2. any files and directories created in /foo is automatically readable/writable by all users in bar

I am not sure what is the best way to do this:

  1. I can set the group of /foo and its initial content to be in the bar group with chown -R :bar and set the setgid it on these with chmod -R g+s. I leave the umask to the default (02). There may be weird side effects to setgid on files too (the libmagic filetype get prefixed with setgid, with unpredictable results for apps that use this).

  2. Or I set the umask to something else for all users (say 03 or 07) but I am not sure I can get the right sharing to take place short of also using the setgid bit.

My question: what is the best, cleanest and idiomatic way to achieve this file sharing setup reliably?

PS: I wrote in the title "peacefully sharing a directory" as a tongue-in-cheek and by this I mean reliably and consistently. I think I have never been able to achieve this sharing reliably without rogue files popping up and not being accessible to the group with any setting I could try.

  • 1
    Pity it isn't NFS. allsquash + anonuid/anongid works pretty well for this. – muru Apr 21 '21 at 09:25
  • @muru but using NFS where everything is only local would create its share of problems and possible performance issues, would it? – Philippe Ombredanne Apr 21 '21 at 09:43
  • Yes. NFS from localhost has caused kernel panics for me, and I had to stop using it. ACLs might be simpler: https://unix.stackexchange.com/a/12847/70524 – muru Apr 21 '21 at 10:17

0 Answers0