Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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:

    IdentityFile ~/.ssh/id_one
    IdentityFile ~/.ssh/id_two
Host *
    IdentityFile ~/.ssh/

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
I personally like my SSH keys named after the doors they open -- username-server_ed25519. – stueja Jun 10 at 17:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .