SSH – How to Specify Key in SSHFS

key-authenticationsshsshfs

I've got a question that I've not been able to find an answer for. I have two computers, both of which run Ubuntu Linux 12.04. I have set up my first computer ("home") to be able to SSH into my second computer ("remote") using public/private RSA key authentication.

This is not the first SSH connection that have set up using key authentication on my home computer, so my home computer has several id_rsa private keyfiles (each of which is for a different computer to SSH into). Thus, I am able to successfully SSH only when I specify a keyfile (in ssh, the -i option), using ssh username@ipaddress -i path/to/keyfile/id_rsa.2.

That works great. However, I would also like to use sshfs, which mounts the remote filesystem. While ssh seems to play nice with multiple keys, I can't find a way to get sshfs to use the correct private key ("id_rsa.2").

Is there a way to get sshfs to do this?

Best Answer

Here's what works for me:

sshfs me@x.x.x.x:/remote/path /local/path/ -o IdentityFile=/path/to/key

You can figure this out via man sshfs:

-o SSHOPT=VAL ssh options (see man ssh_config)

man ssh_config

IdentityFile

Specifies a file from which the user's DSA, ECDSA or DSA authen‐ tication identity is read.

Related Question