Automatically mount sshfs on startup?

Is it possible to automatically mount a sshfs filesystem whenever the connection goes up?


I found the easiest way to achieve this is to create a small script for the process and add it to the start up applications list. Add these two lines to a text file and save it somewhere you'll remember as something like sshfs.sh than add it to start up.

#! /bin/bash
sshfs <host>@<ip>: ~/<mountpoint>

Be sure to create the folder before launching the script or it will have no where to mount the file system you are connecting to. The mount point can be wherever you want I just create it in my home folder.


Does Upstart in Ubuntu work with network events? For sure you can place scripts in /etc/network/if-up.d and /etc/network/if-down.d. There is a guide on Ubuntu Forums.

Does this help enough?


So if sshfs can be listed in /etc/fstab (I believe it can be), then mountall will mount it any time a network device is brought up. The issue is that when the net device goes down, you need to umount it. This would be doable with an upstart job like /etc/init/sshfs-down.conf:

# sshfs-down

start on net-device-down IFACE!=lo
task

exec umount /path/to/sshfs/mount

One problem will probably arise that sshfs may try to flush buffers on umount, and at the point that the net device is already down, you'll have issues.