Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have generated a pair of private/pub RSA keys. The public key is added to the remote server, however, when I connect to the remote server via ssh, through using -v, I can see that my local client is not using the private key in ~/.ssh . How can I add the private key to be sure it is used for authentication?

Hers the verbose output on ssh auth:

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/nubela/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/nubela/.ssh/identity
debug1: Trying private key: /home/nubela/.ssh/id_dsa
debug1: No more authentication methods to try.

Heres the ls -al of my ~/.ssh

[nubela@localhost .ssh]$ pwd
/home/nubela/.ssh
[nubela@localhost .ssh]$ ls -al
total 36
drwx------  2 nubela guest 4096 2009-11-11 12:28 ./
drwx--x--x 70 nubela guest 4096 2009-11-11 00:53 ../
-rw-r--r--  1 nubela guest 1486 2009-11-11 12:25 2.ppk
-rw-------  1 nubela guest  604 2009-06-09 04:37 authorized_keys2
-rw-------  1 nubela guest 1743 2009-11-03 23:48 id_rsa
-rw-r--r--  1 nubela guest  398 2009-11-03 23:48 id_rsa.pub
-rw-r--r--  1 nubela guest 2803 2009-11-11 13:34 known_hosts
-rw-------  1 nubela guest 1743 2009-11-11 12:21 upperstorey
-rw-------  1 nubela guest  398 2009-11-11 12:21 upperstorey.pub

upperstorey is the private key that I want the ssh client to be used. How can I add it?

PS: using -i /path/to/privatekey works

Thanks!

share|improve this question

1 Answer 1

up vote 8 down vote accepted

So, when connecting to host remotehost, you want to use the key contained in upperstorey?

You need to tell ssh to use it explicitly. The easiest way of doing so is adding the following block to your ~/.ssh/config:

Host remotehost
    IdentityFile ~/.ssh/upperstorey

This tells ssh to use that key when connecting to that host. Add any aliases to the Host line (i.e. remotehost, remotehost.remotedomain.com, etc)

share|improve this answer
    
It's worth noting that the '-i' option appends the file to your key search path instead of explicitly using that key. I would presume the 'IdentifyFile' directive works the same way. Thankfully, 99.9999% of the time this distinction doesn't matter. –  Scott Pack Nov 11 '09 at 13:43
    
Testing with 'ssh -v -i identityfile host' seems to indicate it will use only that file. It'll use more than one if more than one is explictly specified. YMMV. –  MikeyB Nov 12 '09 at 22:55

Your Answer

 
discard

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