1

If user A is member of group foo, is it then possible for A to share a file for all members within foo without root permissions?

chown foo:foo file 

Is not permitted without privileges.

A can say

chmod o+rw file

but if A do not want to make it public for other users than those within foo, that does not work.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
user877329
  • 721
  • 5
  • 22
  • possible duplicate of [Permission denied to change gid(group) of a file I own](http://unix.stackexchange.com/questions/113774/permission-denied-to-change-gidgroup-of-a-file-i-own) – enedil May 04 '14 at 15:57
  • 1
    I am not really interested in why chown approach does not work. Rather, I want to create a solution for cooperative work that relies on group permissions that does not requier to much user privileges. – user877329 May 04 '14 at 16:01
  • 1
    *`chown foo:foo file` Is not permitted without privileges.* -> It's also not permitted with privileges if `foo` is not a group. If you want to share by changing just the group, just change the group: `chown :foo file` (does not require privileges). – goldilocks May 04 '14 at 16:13

2 Answers2

4

I found that the command chgrp does the trick:

chgrp foo file
user877329
  • 721
  • 5
  • 22
1

You can create a directory for the group where you want the shared files to live.

Then, you can set setgid bit on the directory, which forces all newly created files to inherit the group from the parent directory. This way you don't need to chgrp the files.

So, for example:

mkdir /shared
chgrp sharegroup /shared
chmod g+swr /shared

Now, if any user creates a files in /shared, its owner will be that user and group will be sharegroup.

You also need to make sure that the default umask for users is 0664, which means group members can write to files too.

Tero Kilkanen
  • 624
  • 4
  • 7
  • This solution is better than having to change the group for every file. If the user moves the file to the shared directory he probably intended to share it. – user877329 May 05 '14 at 15:12