Automount sshfs using fstab without mount -a

24

11

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

user21886

Posted 2013-11-04T11:00:30.787

Reputation: 353

Answers

18

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

MariusMatutiae

Posted 2013-11-04T11:00:30.787

Reputation: 41 321

"Perpaphs the issue is my configuration - my ethernet network is up 5-15 seconds after xfce (and desktop env.) is up. I don't know why ubuntu works like this."

You don't ? Ask NetworkManager, or whoever wrote that ... #! If it is a wireless connection, good luck configuring it, if it is wired, you should NOT have it managed by NetworkMangler. – user2531336 – 2015-04-30T12:46:53.090

read: Connection reset by peer – Dims – 2019-06-24T15:21:32.573

It looks like almost exactly same fstab line as mine (except permissions and symlink option) Anyway I tried it, and no success. I still have to exec mount -a after boot – user21886 – 2013-11-04T11:41:51.113

That's funny, it just worked for another user http://superuser.com/questions/666739/automatically-mount-a-remote-folder-on-boot/666775#666775. Have you checked that you are user 1000,1000, and that your key in id_rsa?

– MariusMatutiae – 2013-11-04T12:22:00.553

Yes, and it is working 100%, but I need to run mount -a after boot. I'm concidering to add mount -a to autostart – user21886 – 2013-11-04T12:50:16.290

It is possible this occurs before your network comes up after execution of mount at boot. Try adding these two lines in rc.local sleep 10: mount -a – MariusMatutiae – 2013-11-04T13:23:55.817

Still no success. Perpaphs the issue is my configuration - my ethernet network is up 5-15 seconds after xfce (and desktop env.) is up. I don't know why ubuntu works like this. My arch connects before xfce etc. – user21886 – 2013-11-04T13:43:19.233

What is relevant to you is whether this can be done at all during boot. So, perhaps you may try sleep 120; mount -a, just to see whether the diagnosis above is correct, or whether we are facing something more fundamental. – MariusMatutiae – 2013-11-04T14:30:53.647

Sleep 120 doesn't work neither – user21886 – 2013-11-04T14:44:27.277

Can you replace "allow-hotplug" with "auto" in /etc/network/interfaces? This will bring up the network before any services that depends on it. (However this is NOT what "auto" means, see man 5 interfaces for more details.) – dash17291 – 2013-11-23T14:54:16.593

4

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

DmitrySandalov

Posted 2013-11-04T11:00:30.787

Reputation: 506

2

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

SkyRaT

Posted 2013-11-04T11:00:30.787

Reputation: 474

0

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

kheraud

Posted 2013-11-04T11:00:30.787

Reputation: 121