HowTo: Create a shared directory for local users (with bindfs).
The information in this thread has been moved to https://help.ubuntu.com/community/Bi...toryLocalUsers
A thread for discussion of the wiki page only can be found here http://ubuntuforums.org/showthread.p...8#post12062098
Thread closed.
Before you start
This guide assumes that you already know:
Introduction
The guide is aimed to show you how to allow multiple local users to read and write (create, delete, rename, modify...) all files (including newly created ones) from a shared directory and its subdirectories. If you want to set up more advanced permissions for different users and/or group try ACLs.
About bindfs
bindfs is a FUSE filesystem for mounting a directory to another location (mountpoint), with permission settings. It allows you to specify the ownership and permissions of the files from inside the mountpoint.
Steps
1. Installing bindfs
2. Create the shared directory
3. Setting the permissions with bindfs
4. Testing the settings (Tips & Tricks)
5. Setting the permissions at boot time
Method 1 - fstab
Method 2 - Upstart
6. That's all :)
1. Installing bindfs
Since Ubuntu 8.10 (Intrepid Ibex), bindfs is in the unverse repository.
- Make sure that the repo is enabled, open up a terminal and run:
Code:
sudo software-properties-gtk --enable-component universe
sudo apt-get update
- Install it:
Code:
sudo apt-get install bindfs
If you are using 8.04 (Hardy Heron), you can install it from this ppa repository or compile it by hand.
2. Createing the shared directory
- e.g. in the /home directory:
Code:
sudo mkdir /home/shared
NOTE: If the directory already exist skip this step.
- allow only root to access it, we will set the permissions later with bindfs:
Code:
sudo chown root: /home/shared
sudo chmod 0700 /home/shared
3. Setting the permissions with bindfs
- Now use the bindfs command to mount the shared directory with altered permissions.
Syntax of the command:
Code:
bindfs [options] dir mountpoint
1. example:
Code:
sudo bindfs -o perms=0700,mirror-only=user1:user2:user3 /home/shared /home/shared
perms=0700 sets the permissions to 0700 (read/write for the owner, none for the group and other);
mirror-only=user1:user2:user3: user1, user2 and user3 will see itself as the owner of the files (user names are separated by a colon).
2. example:
Code:
sudo bindfs -o perms=0750,mirror=user1:user2:user3,group=groupX /home/shared /home/shared
perms=0750 sets the permissions to 0750 (read/write for the owner, read permission for the group and none for other);
group=groupX makes all files owned by the group groupX
For more options, see:
- To unmount the directory:
Code:
sudo umount /home/shared
4. Testing the settings (Tips & Tricks)
Log in as user1 (user2, user3...) and try to create/delete/rename files in the shared direcctory. You can use the CLI for testing:
- To try out different permissions you have to unmount the directory (3.ii.) then remount it with different permissions (3.i.).
- You can use su or sudo to log in as a different user:
Code:
sudo -u username -i
su prompts for the target user's (username's) password, while sudo prompts for your admin password.
To log out the user press Ctrl+d or run:
- You can run the file manager as a different user.
1. Allow the user to connect to the X server:
Code:
xhost +SI:localuser:username
2. Run the file manager:
Code:
sudo -u username -i nautilus /home/shared
3. Test the permissions, then close the file manager.
4. Remove the user form the list of allowed users to connect to the X server:
Code:
xhost -SI:localuser:username
5. Setting the permissions at boot time
Method 1 - fstab
NOTE: Because of a BUG in mountall this method doesn't work, in Ubuntu 9.10 or higher (including Natty 11.04 Alpha-1), if the shared directory is not on the root (/) partition. For a workaround see Method 2 - Upstart below.
- Backup the fstab file:
Code:
sudo cp /etc/fstab{,-backup}
- Open it in a text editor:
Code:
gksu gedit /etc/fstab
- Add an entry at the end of the file. The syntax of an entry:
Code:
bindfs#/path/to/dir /path/to/dir fuse options 0 0
1. example:
Code:
bindfs#/home/shared /home/shared fuse perms=0700,mirror-only=user1:user2:user3 0 0
2. example:
Code:
bindfs#/home/shared /home/shared fuse perms=0750,mirror=user1:user2:user3,group=groupX 0 0
- Save the file and exit.
- Unmount the partition and mount all filesystems mentioned in fstab to check if the entry works as expected:
Code:
sudo umount /home/shared
sudo mount -a
- If something went wrong, restore the original fstab file:
Code:
sudo cp /etc/fstab{-backup,}
Or edit it and remove the line you added.
Method 2 - Upstart
NOTE: This method should work in Ubuntu 9.10 or higher. If you are using an earlier release the fstab method is preferred.
We need to create an Upstart job, which executes the bindfs command after all filesystems are mounted.
- Create the job file and open it for editing:
Code:
gksu gedit /etc/init/mount-bindfs.conf
- Paste the following code into the file:
Code:
# Remount directories with bindfs
#
# Temporary workaround until BUG 503003 is fixed
#
description "Remount directories with different permissions"
start on stopped mountall
script
bindfs -o perms=0700,mirror-only=user1:user2:user3 /home/shared /home/shared
end script
- Adjust the bindfs options and mount point to fit your needs. Save the file and exit.
- Unmount the partition and start the Upstart job to check if it works as expected:
Code:
sudo umount /home/shared
sudo initctl start mount-bindfs
- If something went wrong remove the job file:
Code:
sudo rm /etc/init/mount-bindfs.conf
6. That's all
Copy the files you want to share with the other users in the directory (/home/shared). :)
Links
http://code.google.com/p/bindfs/
community/FilePermissions
HowTo: Use ACLs
Questions? Suggestions?
Re: HowTo: Create shared directory for local users (with bindfs).
Looks like a good tutorial. I haven't had a chance to try it yet, but curious as to what the benefit of this is over simply adding all of your target users to a regular group, making the folder writable by the group and enabling the group access to all future files.
Other then with bindfs, where all users think they own all the files (which I'm not convinced is a good thing. ;)), both solutions would appear to work the same. Is that a correct interpretation, or are their other benefits gained here?
Re: HowTo: Create shared directory for local users (with bindfs).
Quote:
Originally Posted by
CornMaster
Looks like a good tutorial. I haven't had a chance to try it yet, but curious as to what the benefit of this is over simply adding all of your target users to a regular group, making the folder writable by the group and enabling the group access to all future files.
Other then with bindfs, where all users think they own all the files (which I'm not convinced is a good thing. ;)), both solutions would appear to work the same. Is that a correct interpretation, or are their other benefits gained here?
The main benefit is that the new files created in the shared directory will inherit the ownership & permissions.
Re: HowTo: Create shared directory for local users (with bindfs).
I hope you don't mind this because I think BINDFS is a gift and I wouldn't have known about it if not for you, but I have a few suggestions:
ITEM 2i/2ii
You're creating a directory "/home/shared" then chmod'ed directory "/media/shared". I would vote for /home/shared because automounting /media/shared will cause an icon on the desktop. When a user tries to unmount it ( he has no need to unmount it but he'll still try ) he can't because he's not root.
ITEM 3
You might want to show them how to unmount it from the terminal. It may not be obvious how one does that.
ITEM 3.i.2
Most likely I need to read the manual more carefully but I can't get past this example.
When I first read it I interpreted it to mean that user1,2,3, AND groupX had read / write permissions but it doesn't work. Something like this does:
Quote:
sudo bindfs -o perms=0750,mirror-only=user1:user2:user3:@groupX /media/shared /media/shared
Then I figured that what it meant was that user1,2, and 3 related to the "7" in "perms" and groupX related to the "5". But that doesn't work either because "mirror-only" blocks the group out. The only way I can get this to work under this assumption is this way:
Code:
sudo bindfs -o perms=0750,mirror=user1:user2:user3,group=groupX /media/shared /media/shared
Again, on item 3.i.2, if this is just a case of me not reading the manual I will not be offended by being told so :wink:
Re: HowTo: Create shared directory for local users (with bindfs).
Quote:
Originally Posted by
Morbius1
I hope you don't mind this because I think BINDFS is a gift and I wouldn't have known about it if not for you, but I have a few suggestions:
ITEM 2i/2ii
You're creating a directory "/home/shared" then chmod'ed directory "/media/shared". I would vote for /home/shared because automounting /media/shared will cause an icon on the desktop. When a user tries to unmount it ( he has no need to unmount it but he'll still try ) he can't because he's not root.
ITEM 3
You might want to show them how to unmount it from the terminal. It may not be obvious how one does that.
fixed ;)
Quote:
Originally Posted by
Morbius1
ITEM 3.2
Most likely I need to read the manual more carefully but I can't get past this example.
When I first read it I interpreted it to mean that user1,2,3, AND groupX had read / write permissions but it doesn't work. Something like this does:
Then I figured that what it meant was that user1,2, and 3 related to the "7" in "perms" and groupX related to the "5". But that doesn't work either because "mirror-only" blocks the group out. The only way I can get this to work under this assumption is this way:
Code:
sudo bindfs -o perms=0750,mirror=user1:user2:user3,group=groupX /media/shared /media/shared
Again, on item 3.2, if this is just a case of me not reading the manual I will not be offended by being told so :wink:
@group in the mirror mount options means that all members of the group will see themselves as the owner of all files.
Yes, you're right, you can't use mirror-only & group together. (fixed!)
Thank you very much!
Re: HowTo: Create shared directory for local users (with bindfs).
I've been using bindfs in 9.04 and everything has worked just as you're described it, but now that I'm in 10.04 it's not working as expected.
For example I have these two fstab lines in both 9.04 and 10.04 ( I multi-boot ):
Code:
LABEL=Data /DATA ext3 defaults 0 2
bindfs#/DATA /DATA fuse perms=0666:+X 0 0
In 9.04 everything works as expected. In 10.04 the /DATA mount point is empty.
I can recreate the error in 10.04 by commenting out both lines in fstab then:
- adding the bindfs line first followed by a sudo mount -a
- then adding the normal mount line for /DATA followed by a sudo mount -a.
I receive an error: mount: according to mtab, bindfs is already mounted on /DATA
And the partition is empty. Based on this it would appear that the bindfs line is being executed before the normal mount line. Maybe there was some kind of mechanism that prevented that from happening in 9.04 and now it's missing. Or maybe the accelerated boot process in 10.04 has claimed another victim.
Anyway, this is a long winded way of asking you if you have had any problems using bindfs in 10.04.
Re: HowTo: Create shared directory for local users (with bindfs).
Quote:
Originally Posted by
Morbius1
Or maybe the accelerated boot process in 10.04 has claimed another victim.
Probably... I have read about similar issues with network shares (cifs and/or nfs).
Quote:
Originally Posted by
Morbius1
Anyway, this is a long winded way of asking you if you have had any problems using bindfs in 10.04.
To be honest I don't use bindfs (and I also upgraded my Ubuntu installation to maverick :)), but I will try investigate this tomorrow (or today :), it's 2:38am here).
Re: HowTo: Create a shared directory for local users (with bindfs).
Very interesting! Thanks for posting this! :)
Re: HowTo: Create shared directory for local users (with bindfs).
Well, I'm not smart enough to know why this is happening but I have found out how to avoid the problem.
You can't bind a directory to itself in 10.04. At least you can't bind a mount point to itself.
If I have this in fstab 10.04 fails but 9.04 does not:
Code:
LABEL=Data /DATA ext3 defaults 0 2
bindfs#/DATA /DATA fuse perms=0666:+X 0 0
But if I change the bindfs mount point to something else it works:
Code:
LABEL=Data /DATA ext3 defaults 0 2
bindfs#/DATA /home/Shared fuse perms=0666:+X 0 0
It's worked through 5 reboots anyway.:wink:
Re: HowTo: Create shared directory for local users (with bindfs).
Quote:
Originally Posted by
Morbius1
Well, I'm not smart enough to know why this is happening but I have found out how to avoid the problem.
You can't bind a directory to itself in 10.04. At least you can't bind a mount point to itself.
If I have this in fstab 10.04 fails but 9.04 does not:
Code:
LABEL=Data /DATA ext3 defaults 0 2
bindfs#/DATA /DATA fuse perms=0666:+X 0 0
But if I change the bindfs mount point to something else it works:
Code:
LABEL=Data /DATA ext3 defaults 0 2
bindfs#/DATA /home/Shared fuse perms=0666:+X 0 0
It's worked through 5 reboots anyway.:wink:
This only happens when you try to remount a whole partition. I found another workaround ;), see the OP.
Quote:
Originally Posted by
albinootje
Very interesting! Thanks for posting this! :)
You're welcome!