I am using sshfs with a password protected key pair to mount a remote folder using a shell script. I am also using ssh in that script.

Every time I start the shell script I get a password request on the command line for each single sshfs call. I need to prevent that.

Is there a way to use sshfs with ssh-agent and/or kwallet (like I do for ssh)? Or can I reuse an existing ssh connection with sshfs?

2 Answers 2


Are you starting sshfs from your shell, or from a boot-time script?

If you are starting it from your shell, and provided you have a running ssh-agent, it should just work:

$ ssh-add -l
2048 SHA256:XXXXX /home/ji/.ssh/id_rsa (RSA)
$ echo success > foo
$ scp foo ins:
$ rm foo
$ mkdir /tmp/j
$ sshfs ins: /tmp/j
$ cat /tmp/j/foo

If you are starting it from a location that does not already have SSH_AUTH_SOCK in its environment, and assuming the ssh-agent is already active and has the key, you can simply set SSH_AUTH_SOCK to the correct value, which you can either get by running ps uxeww | grep SSH_AUTH_SOCK and massaging the output, or simply looking at whichever /tmp/ssh-*/* socket you can access and using that! I assume you can write a simple shell script to do that!

  • I started a script from the shell. That script contained multiple sshfs calls each one requesting the same password again and again. Commented May 14, 2016 at 8:22
  • I can confirm. sshfs ignores the ssh-agent. I wonder if it has something to do with it being run in "sudo" mode, and ssh-agent not. Commented May 14, 2016 at 8:29
  • you didn't say that in your original post. Of course you can't use someone else's ssh-agent, even if you are root. If you want to sshfs mount as root, run an ssh agent as root!
    – JayEye
    Commented May 14, 2016 at 15:24
  • @Łuaksz: Did you try without sudo? My script runs without sudo (mount-points are in ~) and it also doesn't work. Commented May 14, 2016 at 17:02
  • @Silicomancer Actually my bad, it started to work without sudo. I'm not sure what I did wrong before, as I think I checked it. The only thing is that to unmount without sudo I have to use fusermount -u PATH. Commented May 20, 2016 at 6:01
  1. Uncomment (or add line) user_allow_other to /etc/fuse.conf
  2. Run mount without sudo

sshfs runs in foreground which is fine with me. Don't want to leave around remote mounts and have a potential accident in prod systems.

You must log in to answer this question.

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