I followed instructions for sshfs "on demand" mounting, but it doesn't work.

I added this to /etc/fstab:

username@hostname:/ /mnt/remotes/hostname fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=/home/stanley/.ssh/my_rsa_key,allow_other,reconnect 0 0

Then I ran sudo mount -a which did nothing. I also tried systemctl daemon-reload && systemctl restart proc-sys-fs-binfmt_misc.automount.

So I followed the troubleshooting tips, and used this instead:

username@hostname:/ /mnt/remotes/hostname fuse.sshfs ssh_command=ssh\040-vv,sshfs_debug,debug,_netdev,users,idmap=user,IdentityFile=/home/stanley/.ssh/my_rsa_key,allow_other,reconnect 0 0

And then ran sudo mount -av. In a separate terminal I could access that mount point.

So 1) ssh and sftp are working, 2) sshfs is working, 3) permissions are fine.

So only the on-demand part isn't working - what am I doing wrong?

  • By the way, I know about autofs, but I don't want to use it because it only works for root.
    – lonix
    Sep 5, 2018 at 16:59
  • it is preferred to use the "edit" link underneath the answer to update it, rather than adding separate comments.
    – sourcejedi
    Sep 5, 2018 at 17:53
  • The comment has nothing to do with the question, I'm expecting an answer of the "why don't you rather use tool XYZ", so I tried to avoid it :)
    – lonix
    Sep 5, 2018 at 18:29

3 Answers 3


The instructions are confusing, especially for someone who doesn't understand systemd.

The correct procedure:

  1. add to /etc/fstab: username@hostname:/ /mnt/remotes/hostname fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=/home/stanley/.ssh/my_rsa_key,allow_other,reconnect 0 0

  2. run sudo systemctl daemon-reload. This creates a systemd "unit file".

  3. find out which unit file by running systemctl list-unit-files --type automount. For me it was mnt-remotes-hostname.automount.

  4. enable it: sudo systemctl restart mnt-remotes-hostname.automount.

  5. cd /mnt/remotes/hostname or ls /mnt/remotes/hostname and it will automatically create the sftp connection!

That works, but I'm not yet sure about:

  • some say allow_other is a security risk, I'll need to look into that
  • I don't know how to specify when the mount should be automatically unmounted (how many seconds of idle time, etc.)

If anyone can shed light on that, please do.

UPDATE As per @sourcejedis's answer, stopping the mount must be done in this order: systemctl stop whatever.mount && systemctl stop whatever.automount and one should NOT use umount mounpoint!

  • 2
    allow_other should not allow privilege escalation, only denial of service (cause process to hang, it can be killed though). I wouldn't enable it if you don't want the feature it provides, but if you do then I would just do it :-).
    – sourcejedi
    Sep 5, 2018 at 20:43
  • 2
    x-systemd.idle-timeout= as per man systemd.mount
    – sourcejedi
    Sep 5, 2018 at 20:44
  • @sourcejedi Thanks for those missing pieces of the puzzle!
    – lonix
    Sep 6, 2018 at 5:56

The instructions say:

Note: After editing /etc/fstab, (re)start the required service: systemctl daemon-reload && systemctl restart where <target> can be found by running systemctl list-unit-files --type automount

You have a problem :-(.

Mount options which are implemented by systemd, such as x-systemd.*, are not implemented by the mount command.

But the mount command is what you need to use, if you are an unprivileged user (no root/sudo), and you want to mount an fstab entry (which has been marked to allow this using the user or users mount option).

  • I should have mentioned, I did that too - didn't help - systemctl daemon-reload && systemctl restart proc-sys-fs-binfmt_misc.automount
    – lonix
    Sep 5, 2018 at 18:27
  • Okay the order I issued the commands in was wrong (the instructions are confusing) and so I used the wrong unit file. I added a step by step answer to help anyone else. But you led me the right direction so thank you.
    – lonix
    Sep 6, 2018 at 6:03
  • One more thing: to unmount, is it correct to use unmount mountpoint or to use sudo systemctl stop mnt-remotes-hostname.automount? You mentioned systemd doesn't work with mount, so do I assume the same for umount? (both ways work, so I'm unsure which is safer/correct)
    – lonix
    Sep 6, 2018 at 7:07
  • 1
    But I'm a bit worried about systemctl stop whatever.automount if you haven't already stopped the mount unit, after reading github.com/systemd/systemd/issues/6754
    – sourcejedi
    Sep 6, 2018 at 7:51
  • 2
    Ok so I'll always do systemctl stop whatever.mount && systemctl stop whatever.automount to be on the safe side, and never use umount. Thanks for the warning.
    – lonix
    Sep 6, 2018 at 8:16

I know it's a really old post, but I just set up an sshfs and ran into a similar issue. For me the solution was to generate a rsa key with no password, because when automounting with systemd automount, you can't be prompted for your identity file password.

  • 1
    Similarly, you may have to manually ssh (or mount /mnt/remotes/hostname) as root first. Otherwise root won't have the server in its .ssh/known_hosts file and may get a confirmation prompt. This prevents the automatic process from authenticating, without printing anything very useful in the logs at either end.
    – realh
    Aug 30, 2021 at 20:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .