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

I want to use different private key files to connect to different SSH servers (ssh://git-server:port/repository). How to manage that? SSH seems to assume the private key file in ~/.ssh/id_rsa.

share|improve this question
up vote 1 down vote accepted

That's why there's the -i option:

-i identity_file

Selects a file from which the identity (private key) for RSA or DSA authentication is read. The default is ~/.ssh/identity for protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for protocol version 2.

Identity files may also be specified on a per-host basis in the configuration file. It is possible to have multiple -i options (and multiple identities specified in configuration files).

If you want to make this permanent, you need to setup your SSH config file and set the according IdentityFile option.


Specifies a file from which the user's DSA, ECDSA or DSA authentication identity is read. […]

If you see a dialog similar to this:

enter image description here

You need to enter your user password for your OS X account. Not your key passphrase, or the remote SSH password. This is because they identity hasn't been stored in the keychain.

According to this tutorial, the following command should add them appropriately:

ssh-add -K
share|improve this answer
OK, I've done that now, but when trying to log in, OS X asks in a separate dialog for the password instead of passphrase. I'm entering the correct passphrase for the private key files, but it still can't log in. Any further ideas? – Mike L. Nov 22 '11 at 15:29
If it asks you for the password, that's the SSH password on the remote machine, not the passphrase for the key. – slhck Nov 22 '11 at 15:32
No, no, it asks me for the password for my private key file - at least that's what the dialog is saying. BTW, without the passphrase SSH could not do anything on the remote machine. – Mike L. Nov 22 '11 at 15:49
Hm. I'm not an expert in SSH, I have to admit. What is that dialog saying exactly? – slhck Nov 22 '11 at 15:59
I've configured IdentityFile = ~/secret/pk-file in ~/.ssh/config and invoke ssh myserver. The occurring dialog says Enter your password for the SSH key "pk-file"., shows a Password input field and two checkboxes (Show password and Remember passwod in my keychain). I'm entering the correct passphrase, but I'm asked 2 more times and then SSH aborts with RSA host key for IP address '' not in list of known hosts. Permission denied (publickey). ( is dummy). – Mike L. Nov 23 '11 at 8:34

The easiest way to accomplish this is with a ssh config file.

cat ~/.ssh/config

HOST *  
     USER root

You can also specify certain subdomains use certain users. Useful if your laptop travels between networks.

HOST 192.168.*.*
     USER homeuser

HOST 10.2.*.*
     USER workuser

You could even configure by domains, and use different ssh keys for different domains.

     USER bill
     IdentityFile ~/.ssh/microsoft/id_rsa

     USER steve
     IdentityFile ~/.ssh/apple/id_rsa
share|improve this answer

You must log in to answer this question.

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