Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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?

share|improve this answer
I believe in newer releases, you should use the network manager scripts for this task, see e.g. this guide. Christopher's link however also covers questions for password and allow_others etc. – Carsten Thiel Jan 11 '11 at 8:36

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

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.

share|improve this answer
another problem is sshfs asks for the password of the user's account folder that you are mounting on the host machine... that would make it hard to mount on startup – Joshua Robison Apr 26 '13 at 1:46

I think the more useful thing to do is automatically mount an sshfs file system on access. autofs can be configured to auto mount sshfs filesystems when you access the mount point and unmount after a timeout.

Have a look at autosshfs, which allows mounting an sshfs (fuse) filesystem with a user's ssh-agent. That solves the usual authentication issue with autofs: since it runs as root it is tricky to set up to authenticate as a user without having to type a passphrase every time.

share|improve this answer

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 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.

share|improve this answer
how do you get around the need for a password to the host machine? – Joshua Robison Apr 26 '13 at 1:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.