Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: HowTo: Create a shared directory for local users (with bindfs).

  1. #1
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    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.

    1. 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

    2. 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


    1. e.g. in the /home directory:
      Code:
      sudo mkdir /home/shared
      NOTE: If the directory already exist skip this step.

    2. 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


    1. 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:
      Code:
      man bindfs
    2. 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:

    1. To try out different permissions you have to unmount the directory (3.ii.) then remount it with different permissions (3.i.).

    2. You can use su or sudo to log in as a different user:
      Code:
      su - username
      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:
      Code:
      exit
    3. 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.

    1. Backup the fstab file:
      Code:
      sudo cp /etc/fstab{,-backup}
    2. Open it in a text editor:
      Code:
      gksu gedit /etc/fstab
    3. 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
    4. Save the file and exit.

    5. 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
    6. 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.


    1. Create the job file and open it for editing:
      Code:
      gksu gedit /etc/init/mount-bindfs.conf
    2. 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
    3. Adjust the bindfs options and mount point to fit your needs. Save the file and exit.

    4. 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
    5. 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?
    Last edited by nothingspecial; June 29th, 2012 at 09:35 AM. Reason: Added new method for mounting the dir at boot.

  2. #2
    Join Date
    Nov 2005
    Location
    St. John's, NL
    Beans
    37
    Distro
    Ubuntu 9.10 Karmic Koala

    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?

  3. #3
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: HowTo: Create shared directory for local users (with bindfs).

    Quote Originally Posted by CornMaster View Post
    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.
    Last edited by sisco311; April 26th, 2010 at 01:47 PM.

  4. #4
    Join Date
    Dec 2009
    Beans
    6,767

    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:
    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
    Last edited by Morbius1; April 26th, 2010 at 07:56 PM.

  5. #5
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: HowTo: Create shared directory for local users (with bindfs).

    Quote Originally Posted by Morbius1 View Post
    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 View Post
    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
    @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!

  6. #6
    Join Date
    Dec 2009
    Beans
    6,767

    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.

  7. #7
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: HowTo: Create shared directory for local users (with bindfs).

    Quote Originally Posted by Morbius1 View Post
    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 View Post
    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).

  8. #8
    Join Date
    Jul 2008
    Location
    Netherlands
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HowTo: Create a shared directory for local users (with bindfs).

    Very interesting! Thanks for posting this!

  9. #9
    Join Date
    Dec 2009
    Beans
    6,767

    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.

  10. #10
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: HowTo: Create shared directory for local users (with bindfs).

    Quote Originally Posted by Morbius1 View Post
    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.
    This only happens when you try to remount a whole partition. I found another workaround , see the OP.

    Quote Originally Posted by albinootje View Post
    Very interesting! Thanks for posting this!
    You're welcome!
    Last edited by sisco311; May 28th, 2010 at 12:07 AM.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •