All Articles

Mount Remote Filesystems Using sshfs and systemd

Following service mounts a remote filesystem to local path /mnt/myfs at boot time using systemd and sshfs with public key auth.

  • [sudo] apt install sshfs
  • Prepare a local folder for the mount point: [sudo] mkdir /mnt/myfs
  • Create a file /lib/systemd/system/mnt-myfs.mount (for recent Ubuntu-based distros) with the following contents replacing {{ ... }} placeholders. If you change the local mount point (Where=...), make sure you rename the mount file accordingly!
Description=Mount remote fs with sshfs


What={{ remote-user }}@{{ remote-server }}:/  
Options=_netdev,allow_other,IdentityFile={{ path-to-ssh-private-key }},reconnect,ServerAliveInterval=30,ServerAliveCountMax=5,x-systemd.automount,uid=1000,gid=1000  
  • [sudo] systemctl daemon-reload
  • [sudo] systemctl enable mnt-myfs.mount
  • [sudo] systemctl start mnt-myfs.mount

You can add ,Cipher=arcfour to the end of Options= if you're using this to mount a filesystem on the Raspberry Pi. Note that this would use a weaker cipher for the SSH connection.

SSHFS is a rock solid alternative to clunky WebDAV or NFS or Samba. Although it comes with significant overhead (FUSE, encryption), for local gigabit ethernet mounts, it does a really good job.