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 [email protected] -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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Here’s what works for me:
sshfs <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d60684d75237523752375">[email protected]</a>:/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 authentication identity is read.
Method 2
What you need to do is specify which private key to use in the ~/.ssh/config file. for example:
Host server1.nixcraft.com
IdentityFile ~/backups/.ssh/id_dsa
Host server2.nixcraft.com
IdentityFile /backup/home/userName/.ssh/id_rsa
Method 3
sshfs -o ssh_command='ssh -i path/to/keyfile/id_rsa.2' <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93e6e0f6e1fdf2fef6d3fae3f2f7f7e1f6e0e0">[email protected]</a>:/path /local/path
Method 4
Adding to the solution proposed by @Steven You, a simple solution is :
- go to
~/.ssh/config
Host <nick name>
HostName <ipaddress>
User <username>
PubKeyAuthentication yes
IdentityFile <path/to/keyfile/id_rsa.2>
sshfs -p 22 <nick name>:source/file/on/server local/folder/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0