Created
April 12, 2018 13:25
-
-
Save proprietary/96f6f08758fb98da8467880904191f64 to your computer and use it in GitHub Desktop.
systemd automount sshfs: how to automatically mount a remote sshfs filesystem with systemd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change the relevant {{ PARTS OF THIS FILE }} for your remote address etc. | |
# Make sure this unit file is named similarly to your mountpoint; e.g., for /mnt/mymountpoint name this file mnt-mymountpoint.mount | |
# On Ubuntu: | |
# $ sudo cp mnt-mymountpoint.mount /lib/systemd/system/ | |
# $ sudo systemctl enable mnt-mymountpoint.mount | |
# $ sudo systemctl start mnt-mymountpoint.mount | |
# On Fedora: | |
# $ sudo cp mnt-mymountpoint.mount /etc/systemd/system | |
# $ sudo systemctl enable mnt-mymountpoint.mount | |
# $ sudo systemctl start mnt-mymountpoint.mount | |
[Unit] | |
Description=Mount my remote filesystem over sshfs with fuse | |
[Install] | |
WantedBy=multi-user.target | |
[Mount] | |
What={{ USER }}@{{ HOST }}:{{ REMOTE DIR }} | |
Where={{ MOUNTPOINT like /mnt/mymountdir }} | |
Type=fuse.sshfs | |
# I recommend using your SSH key (no password authentication) with the following options so that you don't have to mount every time you boot | |
Options=_netdev,allow_other,IdentityFile=/home/{{ MY LOCAL USER WITH SSH KEY IN ITS HOME DIRECTORY }}/.ssh/id_rsa,reconnect,x-systemd.automount,uid=1000,gid=1000 | |
# Change to your uid and gid as well according to the output of `cat /etc/group` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On a minimal Debian 12 installation that uses the
ifupdown
package, it was a race with the mount units losing. Even after addingAfter=network-online.target
the mount unit was run before DHCP had returned the address resulting in the terseread connection reset by peer
in the journal. Disabling the interface in/etc/network/interfaces
and enablingsystemd-networkd.service
resolved the race.While this was in a QEMU virtual machine, this may be useful for a Debian installation that uses the
ifupdown
package.