Share a Directory With an Another User
The classic Linux way of doing this sort of thing goes something like this:
Create the shared folder:
sudo mkdir /home/shared |
Create the new user's group:
sudo addgroup sharespace |
Change ownership of the shared folder to the new group:
sudo chown :sharespace /home/shared |
Add your desired users to that group:
sudo adduser user1 sharespace |
Repeat for all users.
Now you have some decisions to make about what you want those users to be able to do:
All group users can add to and delete from the folder and can read and but not write to each others files:
sudo chmod 0770 /home/shared
Same as above but only the owner of the file can delete it:
sudo chmod 1770 /home/shared
All group users can add to and delete from the folder and can read and write to each other's files:
sudo chmod 2770 /home/shared
Same as choice 3 except only the owner of the file can delete it:
sudo chmod 3770 /home/shared
A 1
in the first position of the chmod command is the sticky bit which prevents deletion of a file to anyone other than the owner.
A 2
in the first position of the chmod command is the setgid bit which forces all new or copied files to have the group of that folder.
A 3
in the first position of the chmod command is the combination of the sticky (1
) & setgid (+2
) bits.
There is one caveat to all this as far as the setgid bit is concerned. All new files created in and any files copied to that folder will in fact inherit the group of the folder. But not files moved to that folder. Moved files retain the ownership from wherever they were moved from. One way to get past this problem is to use bindfs.
Finally if you want others outside the group to be able to see the files but not change them change the final 0
in the chmod command to a 5
:
sudo chmod 0775 /home/shared |