Mount Remote Volumes on Boot with sshfs and fstab

I need to have a couple of network volumes mounted to my Linux laptop on a continual basis. One of those volumes has NFS file system so an entry in the fstab was easy enough. The other volume is a ClearCase vob on the proprietary MVSF file system. I’ve tried an fstab entry as mvfs but without success.

I have no issues ssh’ing into the box and I have no issue using fuse or sshfs to mount the volume but that required some action on my part, after having logged in to my user account. Instead, I decided to mount my mvfs volume on boot via an sshfs fstab entry. It took me a few tries to sort it out, given that fstab mounts the volume as root user and sometimes the network might not yet be available. In the end, I found the right combination that permits root to mount the volume with my permissions.

Key options are the delay_connect, idmap, identityfile (which maps to your id file), uid and gid.

It is assumed that you have a public and private key file associated with the volume, i.e. you have ssh’d into this volume and can do so without a password. If not, Google it. You also need to ssh into this server at least once once as root, using your user id file. This will allow you to add the server to your root’s known_hosts file. That would look something like this (note the -i flag pointing to the users id file):

$ sudo su
% ssh -i /home/[USER]/.ssh/id_rsa [USER@][SERVER]
The authenticity of host '[hostname] ([IP address])' can't be established.
RSA key fingerprint is [key fingerprint].
Are you sure you want to continue connecting (yes/no)?

The other two options you need to retrieve for this fstab entry to work are the uid and gid of the user. To do this:

$ id [USER]
uid=28054(youruser) gid=10005(Domain Users) groups=10005(Domain Users),4(adm),6(disk),27(sudo)

The last bit of preparation we need for this to work is a folder to mount to. From root, make a directory in mnt and call it whatever you like. For me, I’m calling it labview because it’s a work thing.

$ sudo mkdir -p /mnt/labview

Finally, you’re ready to add your fstab entry. Replace anything in and including brackets ([]) with your settings:

$ sudo su
% echo '[USER@][SERVER]:/[REMOTE/PATH]  /mnt/[FOLDER]  fuse.sshfs delay_connect,_netdev,user,idmap=[USER],transform_symlinks,identityfile=/home/[USER]/.ssh/[ID_FILE],allow_other,default_permissions,uid=[USER_UID_N],gid=[USER_GID_N] 0 0' >> fstab

Restart your computer and your remote network volume should be mounted on your system.


Adam Merrifield


One thought on “Mount Remote Volumes on Boot with sshfs and fstab

  1. Hello, thanks for sharing your tutorial, it was very helpful!
    After trying it out, I found a little mistake in the fstab line you provided: idmap=[USER] should be idmap=user (user is the value, not the username you are using).
    Also, it can be tested out without restarting the computer by doing mount -a (as root): it will read the contents of fstab as on startup (nonetheless it will not test that the race condition between network and mounting is respected).
    Best regards

Leave a Reply