27

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

21

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
  • 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
    Nov 4 '13 at 11:41
  • That's funny, it just worked for another user superuser.com/questions/666739/…. Have you checked that you are user 1000,1000, and that your key in id_rsa? Nov 4 '13 at 12:22
  • 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
    Nov 4 '13 at 12:50
  • 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 Nov 4 '13 at 13:23
  • 2
    read: Connection reset by peer
    – Dims
    Jun 24 '19 at 15:21
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
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).

2

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
  • The options can indeed be found in the manpage, however what is not clear to me is how to write those options in the fstab file. Do you just write them without the -o, but otherwise identical, in the comma separated list of options of fstab?
    – Andyc
    Jul 29 at 10: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.