Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How does ssh look for private key to load?

I know that it does try to load ~/.ssh/id_rsa and after this ~./.ssh/id_dsa.

Now I do have two keys. Is it possible to name them in such way that ssh will pick them up directly?

If not, would it be possible to trick it, and put the second key inside id_dsa file, even if it is an rsa key?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted
  • If a SSH agent is running, ssh tries all keys loaded into the agent.

  • If an -i file option is given, ssh uses the specified key.

  • If IdentityFile is set in the command line or in ~/.ssh/config, ssh uses the specified key. (You can specify the keys per hostname or domain. See the ssh_config(5) manual page.)

  • Otherwise, it uses a hardcoded list {id_ecdsa, id_rsa, id_dsa} in the ~/.ssh directory.

Out of these, ssh-agent might be the most convenient option – it also removes the need to unlock the private key every time. Use ssh-add ~/.ssh/id_dsa to load a key. If an agent is not running, start it with exec ssh-agent bash or using such tools as Keychain. (Normally, such environments as GNOME, Unity or Mac OS X should start an agent automatically.)

If you decide against using ssh-agent, and you need to use different keys for different machines, you can edit ~/.ssh/config:

Host one.example.com
    IdentityFile ~/.ssh/id_one
Host two.example.com
    IdentityFile ~/.ssh/id_two
Host *.foo.org
    IdentityFile ~/.ssh/id_foo.org

Note that the file name has absolutely no meaning to ssh; it will treat both id_dsa and id_asdfghjk identically. This means that you can name a RSA key id_dsa. However, it will not accept two keys in a single file.

share|improve this answer
add comment

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.