9

Say I have a folder which is completely readable by my user. I want it to be mounted to my home folder. I can't use a symlink because I want the files to be exposed at ~/ and I want other programs "not to know" that it's a mount. Is there a fuse program that implements this? The issue with mount is that it requires root privileges.

I'd also appreciate, if I'd be able to mount this directory, not on boot, but on demand - that's because my ~/ is encrypted unless I'm logged in.

3
  • 1
    fstab can have a 'user' option specified on a particular mount. If you set this up once, you can then mount/unmount without being root. Is this an acceptable solution for you?
    – Haxiel
    Commented Aug 2, 2020 at 13:40
  • @Haxiel the answer I already got seems mostly satisfying, but your alternative seems interesting but I'm not sure I fully understand it although I read the relevant manpages. I tried to do something but I got errors on boot. Would it be possible to get an full answer with an fstab entry example? Commented Aug 10, 2020 at 20:15
  • @Haxiel I've also edited the question - I'd like to mount this directory on demand and not on boot. Commented Aug 10, 2020 at 20:17

3 Answers 3

11

Various FUSE utilities can do that. For instance, bindfs can mount a directory to a different location, similarly to what mount --bind would do.

bindfs --no-allow-other /source/directory /mount/point

The --no-allow-other option is needed unless you uncomment user_allow_other in /etc/fuse.conf (but see, below, the note about libfuse for the security implications).

Unmount with:

fusermount -u /mount/point

Note that FUSE file systems currently have known issues/limitations. It's worth mentioning, among other things, the performance cost, the impossibillity to use inotify to monitor file system events occurring on the source file system and the security implications listed in the libfuse GitHub repository's README.

On Linux, a bind mount performed as mount --bind would not have these downsides. But it would require root privileges at least once, to edit your fstab.
Refer to the linked Q/A for a much more detailed coverage of the subject.

4

You could set up /etc/fstab once, with the following entry:

/path/to/original/dir  /path/to/bind/dir  none  bind,rw,user,noauto  0 0 

The mount options specify the following things, in order:

  • bind indicates that this entry is a bind mount.
  • rw specifies that the entry will be mounted in read-write mode.
  • user allows any non-root user to mount the filesystem.
  • noauto specifies that this entry should not be automatically mounted with mount -a and at boot time.

You'll need to set this up once using root privileges. Once the entry is in place, you can perform the mount as a non-root user. Simply run mount /path/to/bind/dir.

A couple of points to note:

  • With the user option, only the same user account that originally mounted the filesystem can perform the unmount. If multiple users are involved, you can look at the users option instead. See man 8 mount for details.
  • The user option implies three other options: noexec (do not permit execution of binaries), nosuid (do not honor setuid/setgid bits) and nodev (do not interpret devices). If you want to restore any of these functionality, append the corresponding option to the end of the list. For example, bind,rw,user,noauto,exec. Keep in mind that there are security implications for these options. See man 8 mount for details.
5
  • that sounds great but I'm getting this error when I mount without root: mount: /home/doron/repos: must be superuser to use mount.. I've added this line to my fstab: /var/src /home/doron/repos none bind,rw,user,noauto 0 0. Commented Aug 11, 2020 at 21:44
  • @DoronBehar That's a bit strange, because the configuration works on my Fedora system. Can you check if you have more than one entry for '/home/doron/repos' in the fstab file?
    – Haxiel
    Commented Aug 12, 2020 at 3:39
  • Definitely it is the only line with /var/src and /home/doron/repos. I've also tried to test whether it'll work only if /var/src has my full permissions, and I'm the owner of, and that didn't work either, failing the same way :/. Commented Aug 12, 2020 at 7:12
  • Is it possible that you have modified the permissions on the mount binary itself? I found a discussion here that may be helpful.
    – Haxiel
    Commented Aug 12, 2020 at 15:27
  • It worked! Thanks again @Haxiel for the dedication, deeply appreciated. Commented Aug 12, 2020 at 20:23
1

See this answer https://unix.stackexchange.com/a/767296/139357 which shows how to do bind mounts as non-root using unshare and nsenter

That answer will be improved upon.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .