HowTo: Multi User Shared Local Directory

Write tutorials and howtos in here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

HowTo: Multi User Shared Local Directory

Postby altair4 on 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
NOTE: Items [3] [4] [5] and [6] will no longer work in any current Mint version because of a bug in the display manager it uses: https://bugs.launchpad.net/linuxmint/+bug/1094990 Bindfs can be used to reproduce [3] and [5]

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

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:
Code: Select all
sudo chmod 0777 /home/Shared


[2] All users can add to but can only delete files they own and can read but not write to each others files:
Code: Select all
sudo chmod 1777 /home/Shared

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:
Code: Select all
sudo chown :plugdev /home/Shared
sudo chmod 2775 /home/Shared

Edit /etc/profile as root: Note: This step from Mint12 forward is no longer necessary as the umask has already been set to 002 for this purpose.
Code: Select all
gksu gedit /etc/profile

Find the line at the bottom that references umask and change it to:
Code: Select all
umask 002

Logout and log back in again since profile is read only once at login.

Note1: You may have to add your users to the plugdev group depending on how you added the user:
Code: Select all
sudo gpasswd -a mary plugdev

Logout and log back in again for the group change to take affect.


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

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:
Code: Select all
sudo groupadd special
sudo gpasswd -a mary special
sudo chown :special /home/Shared
sudo chmod 2770 /home/Shared

Edit /etc/profile as root: Note: This step from Mint12 forward is no longer necessary as the umask has already been set to 002 for this purpose.
Code: Select all
gksu gedit /etc/profile

Find the line at the bottom that references umask and change it to:
Code: Select all
umask 002

Logout and log back in again since profile is read only once at login.

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:
Code: Select all
sudo chmod 3770 /home/Shared
Last edited by altair4 on Fri Jul 04, 2014 7:19 am, edited 6 times in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 15
Level 15
 
Posts: 5798
Joined: Tue Feb 03, 2009 10:27 am

Linux Mint is funded by ads and donations.
 

Re: HowTo: Multi User Shared Local Directory

Postby altair4 on Thu Aug 25, 2011 4:05 pm

METHOD B: Using Bindfs

Please note: This will work in Mint prior to Mint12 and based on where Ubuntu is at the moment it will work in Mint13 and beyound but it will not install in Mint12 because of an infantile mistake in the bindfs package that Ubuntu simply refuses to correct: https://bugs.launchpad.net/ubuntu/+sour ... bug/851600

Initial steps:

[1] Install bindfs
Code: Select all
sudo apt-get install bindfs

[2] Create a shared directory:
Code: Select all
sudo mkdir /home/Shared


Manual Mounts:

[1] Access to all
Code: Select all
sudo bindfs -o perms=0666:+X /home/Shared /home/Shared

All folders and subfolders will have permissions of 777 allowing anyone to access them.
All files will be 666 except those files that are executable to begin with in which case they will be 777.
This will give everyone read / write access to individual files and the ability to execute any files marked as such.

All existing files / folders and any new or copied files / folders will assume these permissions.

[2] You could restrict access to only local login users by modifying the mount command to this:
Code: Select all
sudo bindfs -o perms=0660:+X,group=plugdev /home/Shared /home/Shared

For Mint16 it's:
Code: Select all
sudo bindfs -o perms=0660:+X,force-group=plugdev /home/Shared /home/Shared

[3] You can even restrict it further to a subset of the local login users by creating your own group:
Code: Select all
sudo bindfs -o perms=0660:+X,group=mygroup /home/Shared /home/Shared

For Mint16 it's:
Code: Select all
sudo bindfs -o perms=0660:+X,force-group=mygroup /home/Shared /home/Shared

Then you would have to create the new group:
Code: Select all
sudo groupadd mygroup

And add all your users to that group:
Code: Select all
sudo gpasswd -a mary mygroup


Note: To undo the mounts run the following command:
Code: Select all
sudo umount /home/Shared


Auto Mount at Boot:

[1] Using an Upstart job:

* Create an upstart job file:
Code: Select all
gksu gedit /etc/init/bindfs-mounts.conf

* With this content:
Code: Select all
# Create a common directory using bindfs
description "Multi User Shared Directory"

start on stopped mountall

script
  bindfs -o perms=0666:+X /home/Shared /home/Shared
end script

Change the actual script to whatever options you want to use.

* Save the file, exit gedit, and start the upstart job:

Unmount the partition if you mounted it manually:
Code: Select all
sudo umount /home/Shared

Then start the Upstart job:
Code: Select all
sudo initctl start bindfs-mounts

Check the /home/Shared folder and verify that it's working as you desired.

[2] Using fstab

Warining: There is a problem using this method with Ubuntu based Mint. I tried this method first and it failed - and by failed I mean I could not boot into the machine so I had to remove that line in fstab using a rescue disk. The problem is with Ubuntu and there is a bug report concerning the cause of this issue: https://bugs.launchpad.net/ubuntu/+sour ... bug/503003 .

I can follow the procedure below and after the "sudo mount -a" everything works as advertised but after a reboot it fails because of the bug in mountall. If it's like bind itself the problem does not occur in Debian but I have not tried it in LMDE to verify. So the following is informational only:

The syntax for fstab changes somewhat I'm afraid. So instead of this in a terminal:
sudo bindfs -o perms=0666:+X /home/Shared /home/Shared
It turns to this in fstab:
Code: Select all
bindfs#/home/Shared    /home/Shared    fuse    perms=0666:+X    0    0

And instead of this:
sudo bindfs -o perms=0660:+X,group=plugdev /home/Shared /home/Shared
It turns to this:
Code: Select all
bindfs#/home/Shared    /home/Shared    fuse    perms=0660:+X,group=plugdev    0    0

For Mint16 it's:
Code: Select all
bindfs#/home/Shared    /home/Shared    fuse    perms=0660:+X,force-group=plugdev    0    0


After you add the lines in fstab run the following command which will test for errors and mount the directory:
Code: Select all
sudo mount -a


Further information on bindfs can be found here: http://www.cs.helsinki.fi/u/partel/bind ... dfs.1.html
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 15
Level 15
 
Posts: 5798
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Multi User Shared Local Directory

Postby panorain on Mon Mar 24, 2014 10:48 pm

Thank you, for the wonderful tutorial and your time.

Is there a way to simply add a file folder named 'Shared' to the desktop on Cinnamon/Mate/etc that actually sticks and can be used simply; other than digging into filesystem within Nemo every time one would like to add a file to the '/home/Shared' folder?

Thank you,
Linux Mint 16 Petra. Cinnamon Desktop installed.
User avatar
panorain
Level 1
Level 1
 
Posts: 48
Joined: Mon Dec 16, 2013 3:21 pm

Re: HowTo: Multi User Shared Local Directory

Postby altair4 on Tue Mar 25, 2014 6:42 am

My normal desktop is XFCE where this is easy to do but I never noticed before that Nemo has no "Send To" option in it.

Anyway, right click the desktop > Create a New launcher here:

Name: LocalShare
Command: nemo /home/Shared
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 15
Level 15
 
Posts: 5798
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Multi User Shared Local Directory

Postby panorain on Tue Mar 25, 2014 11:47 pm

Certainly appreciate your response and the research you do.

I cannot tell you how much a noob-beginner like me appreciates your help.

Thank you,
Linux Mint 16 Petra. Cinnamon Desktop installed.
User avatar
panorain
Level 1
Level 1
 
Posts: 48
Joined: Mon Dec 16, 2013 3:21 pm


Return to Tutorials / Howtos

Who is online

Users browsing this forum: DaOg75, Resistor and 7 guests