Traditional fstab mounting often fails for SSHFS because network interfaces may not be ready during early boot stages. Unlike local filesystems, SSHFS requires both network connectivity and SSH service availability before mounting.
Create a systemd service that triggers after network.target:
# /etc/systemd/system/mnt-storage.mount
[Unit]
Description=SSHFS Mount for Storage
After=network-online.target
Wants=network-online.target
[Mount]
What=sshfs#jldugger@storage:/mnt/HD_a2/
Where=/mnt/storage
Type=fuse.sshfs
Options=uid=1000,gid=1000,allow_other,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3
[Install]
WantedBy=multi-user.target
For more resilient mounting that handles disconnections:
# Install autofs
sudo apt install autofs
# /etc/auto.master
/mnt/storage /etc/auto.sshfs --timeout=60
# /etc/auto.sshfs
storage -fstype=fuse.sshfs,port=22,uid=1000,gid=1000,allow_other,reconnect :jldugger@storage:/mnt/HD_a2/
For true headless operation, configure passwordless SSH:
ssh-keygen -t ed25519 -f ~/.ssh/storage_key
ssh-copy-id -i ~/.ssh/storage_key.pub jldugger@storage
# Add to mount options:
IdentityFile=/home/jldugger/.ssh/storage_key
- Check
journalctl -xe
after failed mounts - Test basic SSH connectivity first:
ssh jldugger@storage
- Verify fuse permissions:
lsmod | grep fuse
- Add
debug
to mount options for verbose logging
For better throughput:
Options=...,compression=no,cache=no,large_read,kernel_cache
For latency-sensitive operations:
Options=...,cache=yes,entry_timeout=3600,attr_timeout=3600
Mounting remote filesystems via SSHFS during system boot presents unique challenges, particularly regarding network availability timing. Traditional /etc/fstab
entries often fail because they execute before network interfaces are ready.
Modern Ubuntu systems (15.04+) should use systemd mount units for proper dependency management:
# /etc/systemd/system/mnt-storage.mount
[Unit]
Description=SSHFS Mount for NAS
After=network-online.target
Requires=network-online.target
[Mount]
What=sshfs#jldugger@storage:/mnt/HD_a2/
Where=/mnt/storage
Type=fuse.sshfs
Options=uid=1000,gid=1000,allow_other,reconnect,transform_symlinks,BatchMode=yes,IdentityFile=/home/jldugger/.ssh/id_rsa
[Install]
WantedBy=multi-user.target
Then enable with:
sudo systemctl daemon-reload
sudo systemctl enable mnt-storage.mount
For older Ubuntu versions using Upstart (like 9.04 mentioned), create:
# /etc/init/sshfs-mount.conf
description "Mount SSHFS after network"
start on (local-filesystems and net-device-up IFACE=eth0)
task
exec /bin/mount /mnt/storage
For resilient setups that survive network interruptions:
# /etc/systemd/system/mnt-storage.automount
[Unit]
Description=Automount SSHFS share
[Automount]
Where=/mnt/storage
TimeoutIdleSec=30
[Install]
WantedBy=multi-user.target
# Corresponding mount unit (mnt-storage.mount)
[Mount]
Options=_netdev,x-systemd.automount,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3
Ensure passwordless authentication works:
ssh-keygen -t rsa -b 4096
ssh-copy-id jldugger@storage
chmod 600 ~/.ssh/id_rsa
- Check
journalctl -xe
for mount errors - Test basic SSH connectivity first
- Verify permissions on mount points
- Add
debug
to mount options for verbose logging