3

I wonder if there is something like "user specific /etc/fstab" for fusermount? ~/.fstab, ~/.config/fstab, something the like, which would work in cooperation with FUSE.

I used

sshfs foo.bar: foo.bar/

from the home dir to connect to the remote dir (there is foo.bar directory, and I have .ssh/config set accordingly). But I didn't like the repeating of foo.bar, wanted to use simple command [cmd] foo.bar/ to mount the remote directory. After some googling I found that simple "mount foo.bar/" can be made to work with the following line in /etc/fstab (also needed to enable "user_allow_other" in /etc/fuse.conf)

login@foo.bar:  /home/user/foo.bar  fuse.sshfs  user,IdentityFile=/home/user/.ssh/id_rsa,port=12345,allow_other  0  0

Now "mount foo.bar" works as intended (and "umount" works as well). But it seems kind of odd to edit system-wide file for user-specific purpose; also the settings already in .ssh/config are repeated there (port), the identity file has to be specified. Maintaining this for more sites (users) seems inconvenient and evidently not what /etc/fstab is for. Another oddity - FUSE is run by root (afaictl) when using this solution.

I would much prefer something like "fusermount foo.bar/", with user specific fstab.

Is there such a thing?

0

There's no per-user equivalent of /etc/fstab. You can write a shell script that reads a file of your choice and calls the appropriate mounting command. Note that from the argument foo.bar, you have to deduce multiple pieces of information: the server location foo.bar, the directory on the server (here your home directory), and first and foremost the fact that it's an SSHFS mount.

#!/bin/bash
####
if [ -e ~/.fstab ]; then
  args=("$@")
  ((i=${#args[@]}-1))
  target=${args[$i]}
  while read filesystem mount_point command options comments; do
    if [[ $filesystem = \#* ]]; then continue; fi
    if [[ $mount_point = "$target" || $filesystem = "$target" ]]; then
      if [[ -n $options ]]; then
        args[$((i++))]=-o
        args[$((i++))]=$options
      fi
      args[$((i++))]=$filesystem
      args[$((i++))]=$mount_point
      exec "$3" "${args[@]}"
    fi
  done
fi
## Fall back to mount, which looks in /etc/fstab
mount "$@"

(Warning: untested code.)

This snippet parses a file ~/.fstab with a syntax reminiscent of /etc/fstab: “device”, mount point, filesystem type, options. Note that here the filesystem type is a command to execute and the “device” is filesystem-dependent. Not all FUSE filesystem commands use this syntax with a “device” followed by a mount point, though it's a common convention.

SSH options like the identity file, the remote username, etc. can stay in ~/.ssh/config. The only reason to put them in /etc/fstab is to allow these options to be used by all users.

  • 1
    Thank you for your reply and nice script. Something like "cd $HOME; sshfs $1: $1/" would be quite enough for me, though. But I was interested if I had not missed something, and will probably file a bug report/feature request for fusermount, since IMO user fstab would come handy. Thanks again! – renergy Mar 9 '15 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.