Using a NAS box as 24/7 file server, I'd like to use sshfs to connect to it from an Ubuntu 9.04 desktop. Currently, I have this line in the desktop's fstab:
sshfs#jldugger@storage:/mnt/HD_a2/ /mnt/storage fuse comment=sshfs,auto,users,exec,uid=1000,gid=1000,allow_other,reconnect,transform_symlinks,BatchMode=yes,fsname=sshfs#jldugger@storage/mnt/HD_a2/ 0 0
I can confirm it works with mount /mnt/storage
. What I need is some method of mounting it at startup, but after the network connection is established.
Currently, Upstart in Ubuntu does not generate network events. Instead it calls traditional sysvinit. By default NetworkManager is installed and running; rather than emit network events to upstart, it contains a run-parts dispatcher (/etc/NetworkManager/dispatcher.d/) which itself simply relies on ifupdown's run-parts dispatcher (/etc/network/*.d/). In particular you care about /etc/network/if-up.d/ and /etc/network/if-down.d/
First set up a unencrypted ssh keypair, so you can mount the point without a prompt. Write a script, place it in /etc/network/if-up.d/ and make executable. The following was discovered on UbuntuForums and was sufficient for me:
If you have a wifi or otherwise unreliable connection, place the following in /etc/network/if-down.d/:
Upstart is the preferred method of issuing startup scripts or services in Ubuntu now, although editing
/etc/rc.local
still works. Upstart allows you to control when the service is run, making sure it happens after initiating your network connection.It's also possible to edit the symlinks in /etc/rc.X.d directly, (substitute X for the run-level you are using) and add a name such as S99mount to ensure that it's run after the network setup. This will need to point to a script file that mounts the sshfs you are requesting.
_netdev as a mount option should solve this, I believe
Just a thought, but if you're using this as a file server, maybe NFS or Samba would be a better solution than ssh.
Here is another solution in case you don't have a certificate from your remote host and have to use a login/password instead. I'm using in this example the same username and directories used by jldugger to avoid adding confusion.
Create a file containing your password in your home directory, and secure it:
Edit your
/etc/rc.local
file and insert the following command at the bottom, but before the "exit 0":