3

I am trying to auto mount a folder from my raspberry pi (/home/pi/server_folder), to a local folder (/home/my_name/raspberrypi). I can do this with sshfs (auto mount in fstab) when I set up a blank rsa key, but when I try to use an actual key, like 123, the raspberry pi filesystem wont mount. This is pretty obvious, since I have to supply the passphrase, but is there a way to have it ask for the passphrase when I first try to access /home/my_name/raspberrypi, or do something similar to that? Because if someone gets my laptop, they dont need to put a password or anything in to get access to my raspberry pi, if I leave the rsa key blank. I have looked into autofs, and autosshfs, but autosshfs won't download, and autofs doesn't explain how to mount with an actual rsa key (well, I haven't found a guide on how to). I'm using arch Linux, latest version. Here is the fstab entry:

pi@10.0.0.50:/home/pi/server_folder/ /home/my_name/raspberrypi  fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=/home/my_name/.ssh/id_rsa,allow_other,reconnect 0 0

which is what arch wiki says to do (but doesn't explain very well).

3

Since SSHFS is based on FUSE, it's easier to use a non-root automounter. Use afuse, that's prety much what it was designed for. One-time setup:

mkdir ~/.afuse
ln -s .afuse/raspberrypi/server_folder ~/raspberrypi

To start the automounter:

afuse -o mount_template="sshfs %r:/ %m" -o unmount_template="fusermount -u -z %m" ~/.afuse

Make sure that the SSH_AUTH_SOCK variable is set when you start afuse, i.e. it must be started after ssh-agent. Run ssh-add to load the key into the SSH agent, and then you'll be able to access the SSHFS directories.

  • Is there any way to get it to work after a shutdown? – Vityou Sep 6 '16 at 21:50
  • @Vityou Put the afuse invocation in your session startup scripts (e.g. .profile, .config/autostart, …). – Gilles Sep 6 '16 at 22:05
0

To expand on Gilles' correct answer, and to address some further thoughts addressed in comments to his answer regarding 'Integration of into (profile) startup (scripts)':

You can enable on-demand mounting by adding a script invocation to your e.g. ~/.profile or create a user level systemd service unit.

I favor the answer: ~/.config/systemd/user/afuse.service

[Unit]
Description="SSHFS via Afuse automounter"
AssertPathExists=%h/scp/
AssertFileIsExecutable=/usr/bin/afuse
AssertFileIsExecutable=/usr/bin/sshfs

[Service]
Type=forking
WorkingDirectory=%h/scp
ExecStart=/usr/bin/afuse \
    -o mount_template="sshfs -o ServerAliveInterval=10 -o reconnect %%r:/ %%m" \
    -o unmount_template="fusermount -u -z %%m" .
Restart=always
PrivateTmp=true
#NoNewPrivileges=true
#Environment=

[Install]
WantedBy=default.target

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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