Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

I would be very grateful for any advice you would be willing to offer. Thank you!

share|improve this question
    
Keychain works well for me in this scenario... –  jasonwryan Jan 17 '13 at 0:45

2 Answers 2

up vote 11 down vote accepted

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.

share|improve this answer
    
Thank you! @goldilocks, I completely missed the IdentityFile line in the sshfs man page. That's exactly what I was looking for, as well. I've just tried your solution, and it works perfectly. I appreciate the help! –  J L Jan 17 '13 at 4:09

What you need to do is specify which private key to use in the .ssh/config file like this:

Host server1.nixcraft.com
    IdentityFile ~/backups/.ssh/id_dsa
Host server2.nixcraft.com
    IdentityFile /backup/home/userName/.ssh/id_rsa
share|improve this answer
    
Thanks so much! @Steven You, I didn't realize that sshfs reads .ssh/config files (though I do see now that I missed a similar answer from someone's previous post, at stackoverflow.com/a/13638806/1940466). That's excellent to know. For what it's worth, I would like to accept both your and @goldilocks' answers, but I'm not able to. I also don't have enough reputation to vote up your answer. I very much appreciate the answer, though! –  J L Jan 17 '13 at 4:08
    
Ha, thank you as well. :) –  Steven You Jan 20 '13 at 23:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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