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:
- all users in
bar
can read/write files and directories in/foo
- any files and directories created in
/foo
is automatically readable/writable by all users inbar
I am not sure what is the best way to do this:
I can set the group of
/foo
and its initial content to be in thebar
group withchown -R :bar
and set the setgid it on these withchmod -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 withsetgid,
with unpredictable results for apps that use this).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.
allsquash
+anonuid
/anongid
works pretty well for this. – muru Apr 21 '21 at 09:25