Ubuntu – Use sshfs with ssh-agent and/or kwallet

kwalletsshssh-agentsshfs

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?

Best Answer

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
success

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!

Related Question