ssh has the -i option to tell it which private key file to use when authenticating:

-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 ver-
     sion 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for protocol version 2.  Iden-
     tity 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).

Is there a similar way to tell git which private key file to use when on a system with multiple private keys in the .ssh directory?

link|improve this question

feedback

2 Answers

up vote 21 down vote accepted

In ~/.ssh/config, add:

Host gh
        Hostname github.com
        User git
        IdentityFile ~/.ssh/somekey

Now you can do git clone ssh://gh/username/repo.git.

link|improve this answer
1  
The file specified in IdentityFile is the private key, not the public key. The .pub extension you used in your example confused me, I think it will be more clear to use "IdentityFile ~/.ssh/gh_id_rsa" – Joaquin Cuenca Abela Apr 27 '11 at 9:17
@Joaquin Cuenca Abela: Answer edited. – Laurent Pireyn May 13 '11 at 16:19
feedback

Write a script that calls ssh with the arguments you want, and put the filename of the script in $GIT_SSH. Or just put your configuration in ~/.ssh/config.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.