HowTo: Multi User Shared Local Directory
Posted: Mon Apr 04, 2011 8:30 am
HowTo: Multi User Shared Local Directory
I will offer two methods in this HowTo.
Method A: Using traditional linux ownership and permissions ( the first post in this topic )
Method B: Using Bindfs ( the second post in this topic )
Method A: Using Linux Permissions
Creating a "shared" local directory between multiple local users depends on your definition of "shared". The following are examples of options on how you would set up a shared directory accessible by local users.
I'm going to start by creating the directory to be shared:
This will create a directory with root as owner and with permissions of 755 meaning root can read and write and everyone else can only read.
[1] All users can add to and delete from the folder and can read but not write to each others files:
[2] All users can add to but can only delete files they own and can read but not write to each others files:
Note: The "1" is a "sticky bit": A file in a sticky directory may only be removed or renamed by a user if the user has write permission for the directory and the user is the owner of the file, the owner of the directory, or root.
[3] All users can add to and delete from the folder and can read and write to every file:
Note1: You may have to add your users to the plugdev group depending on how you added the user:
Logout and log back in again for the group change to take affect.[/color]
Note2: The "2" in "chmod 2775" is the setgid bit. All files saved to a directory with that bit set will inherit the group of the directory.
Note3: Changing the global umask from 022 to 002 will force every saved folder / file to save with permissions of 775 / 664. So all users who are members of the group will have read / write access to all new folders / files.
[4] All users can add to but can only delete files they own and can read and write to every file:
Same as [3] above except "sudo chmod 2775 /home/Shared" is changed to this:
Note: the "3" is a combination of the "1" sticky bit + the "2" getgid bit.
[5] Only some users can add and delete from the folder and can read and write to every file:
Note: You are creating a unique group, adding specific users to that group, making the folder accessible only to that group, and making sure every new file added to that directory is write accessible to that group.
[6] Only some users can add to but can only delete files they own and can read and write to every file
Same as [5] except "sudo chmod 2770 /home/Shared" is changed to this:
I will offer two methods in this HowTo.
Method A: Using traditional linux ownership and permissions ( the first post in this topic )
Method B: Using Bindfs ( the second post in this topic )
Method A: Using Linux Permissions
Creating a "shared" local directory between multiple local users depends on your definition of "shared". The following are examples of options on how you would set up a shared directory accessible by local users.
I'm going to start by creating the directory to be shared:
Code: Select all
sudo mkdir /home/Shared
[1] All users can add to and delete from the folder and can read but not write to each others files:
Code: Select all
sudo chmod 0777 /home/Shared
Code: Select all
sudo chmod 1777 /home/Shared
[3] All users can add to and delete from the folder and can read and write to every file:
Code: Select all
sudo chown :plugdev /home/Shared
sudo chmod 2775 /home/Shared
Code: Select all
sudo gpasswd -a mary plugdev
Note2: The "2" in "chmod 2775" is the setgid bit. All files saved to a directory with that bit set will inherit the group of the directory.
Note3: Changing the global umask from 022 to 002 will force every saved folder / file to save with permissions of 775 / 664. So all users who are members of the group will have read / write access to all new folders / files.
[4] All users can add to but can only delete files they own and can read and write to every file:
Same as [3] above except "sudo chmod 2775 /home/Shared" is changed to this:
Code: Select all
sudo chmod 3775 /home/Shared
[5] Only some users can add and delete from the folder and can read and write to every file:
Code: Select all
sudo groupadd special
sudo gpasswd -a mary special
sudo chown :special /home/Shared
sudo chmod 2770 /home/Shared
[6] Only some users can add to but can only delete files they own and can read and write to every file
Same as [5] except "sudo chmod 2770 /home/Shared" is changed to this:
Code: Select all
sudo chmod 3770 /home/Shared