0

looks like all the "automount SSHFS" are outdated and not working anymore on today desktops.

If I have a microSD card, that is shared via SFTP on an rpi, how can I auto-mount it on eg.: Ubuntu 20.04 desktops?

Tried with ex.:

sshfs#MYUSER@192.168.8.3:/stuff/ /media/user/stuff/  fuse.sshfs noauto,x-systemd.automount,users,idmap=user,IdentityFile=/home/user/.ssh/id_rsa,allow_other,reconnect,port=22 0 0

but it doesn't work.. what only works so far is:

sshfs#MYUSER@192.168.8.3:/stuff/ /media/user/stuff/ fuse defaults,auto,allow_other,noatime,port=22,IdentityFile=/home/user/.ssh/id_rsa,user 0 0

but this requires me to do a "mount -a".. which is not very automatic :)

The question: as a normal user, how can I mount an SSHFS share only on demand? So if I am in that directory (in eg.: GNOME os in the terminal, ls or cd or "cp from tothatshare") Havin SSH key login with no password.

Many Thanks.

jim7475
  • 31

1 Answers1

1

how can I mount an SSHFS share only on demand?

Typically, you do that using systemd (auto)mounts.

You just add a file to your /etc/systemd/system, containing

[Unit]
Description=SSHFS mount
Requires=network-online.target

[Mount] What=sshfs#MYUSER@192.168.8.3:/stuff/ Where=/media/user/stuff/ Type=sshfs Options=allow_other,noatime,port=22,IdentityFile=/home/user/.ssh/id_rsa

The file must be named media-user-stuff.mount (i.e. take what is in Where=, remove the root /, then replace all / with - and end with .mount)

That's a systemd mount file. You can now mount that directory using systemd (but you don't want that, so let's not do that).

Instead, we also write an systemd.automount file: That will make systemd "pseudo-mount" something at the Where=. The first time something tries to access that, the actual mounting takes place.

so, /etc/systemd/system/media-user-stuff.automount:

[Unit]
Description=user media automount

[Automount] Where=/media/user/stuff

[Install] WantedBy=multi-user.target

which you finally enable using systemctl enable --now media-user-stuff.automount. It will hence be "pre-mounted" every system boot.

as a normal user, how can I …

not at all; the automount logic depends on being able to monitor access to a directory, and that takes root privileges. Far as I can see, a wrapper that eradicates that need is not built in currently.


Word about SSHFS: Honestly, there's probably better network file systems; SSHfs really likes to hang and be unrecoverable on connection loss, it's not "clean" in a lot of ways, you can lose data (happened to me!) without noticing, and it's very slow, actually.

Maybe use a different network file system. Samba isn't hard to set up these days.