Automount sshfs using fstab without mount -a

Please consider following fstab line (line breaks for readability):

sshfs#user@192.168.1.123:/home/user/
/home/user/Server/
fuse
auto,user,_netdev,reconnect,uid=1000,gid=1000,IdentityFile=/home/user/.ssh/id_rsa,idmap=user,allow_other
0 

It works fine, but every reboot I need to use mount -a to mount the server (or click appropriate icon in Thunar to mount the thing)

Is it possible to mount my ssh directory straight-away on boot time?

I am using Xubuntu 13.10

4 Answers

The correct syntax for mounting sshfs shares at boot, in the /etc/fstab file is

 USERNAME@HOSTNAME_OR_IP:/REMOTE/DIRECTORY /LOCAL/MOUNTPOINT fuse.sshfs _netdev,user,idmap=user,transform_symlinks,identityfile=/home/USERNAME/.ssh/id_rsa,allow_other,default_permissions,uid=USER_ID_N,gid=USER_GID_N 0 0

It is an adaptation to non-systemd distros of the instructions contained here. If you are instead on a systemd distro (Arch, Fedora, OpenSUSE,...), the suitable instruction is:

USERNAME@HOSTNAME_OR_IP:/REMOTE/DIRECTORY /LOCAL/MOUNTPOINT fuse.sshfs x-systemd.automount,_netdev,user,idmap=user,transform_symlinks,identityfile=/home/USERNAME/.ssh/id_rsa,allow_other,default_permissions,uid=USER_ID_N,gid=USER_GID_N 0 0
11

Try using the delay_connect option.

Full /etc/fstab line:

USER@HOSTNAME:/REMOTE/ /LOCAL/ fuse.sshfs delay_connect,_netdev,user,idmap=user,transform_symlinks,identityfile=/home/USERNAME/.ssh/id_rsa,allow_other,default_permissions,uid=USER_ID_N,gid=USER_GID_N 0 0

Those delay_connect, _netdev, ... are correct but won't work unless you tweak the networking to come up exactly in (or before) that small time window, when the /etc/fstab is being processed. When the processing is over, and networking comes up later, you have to use the mount -a (or friends).

In most cases (and mine also) the network-manager caused the problem, since it brings the network up after login by default. It can be tweaked to bring it up earlier at boot time. If I remember correctly, all you need to do is to check the option Available to all users in the connection properties dialog (or, if you prefer command line, create manually the connection in /etc/NetworkManager/system-connections).

Based on this ubuntu help page and my tries with Debian 9, I make it work and have right file permissions with this fstab entry :

sshfs#user@host:/remote/path /local/path fuse delay_connect,defaults,idmap=user,IdentityFile=/local/path/to/privatekey.pem,port=22,uid=1001,gid=1002,allow_other 0 0

delay_connect ensures fstab does not mount remote folder before network interfaces are up.

You can change port, uid, gid to match your local needs. To figure out my uid / gid I simply used $ id when logged with the right user.

allow_other is there to allow other users / groups to access the mounted directory; Even with the right /local/path permissions (for example 777), this is needed if you want a different user (different from the one mounting the sshfs) to access the mounted directory.

Other options can be found in the sshfs manpage

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like