9

I am in a situation, where I need my msysgit to talk to github with different keys. However git bash insists on using the keyfile named id_rsa ONLY. If I do ssh -vT git@github.com I see only id_rsa being offered.

So whenever I need to use any other key I have to do all this,

ssh-agent bash
ssh-add ~/.ssh/mygithubkey
git clone git@github.com:myaccount/myrepo.git

or rename mygithubkey to id_rsa whenever i need it backing up the original id_rsa to another file anotherkey

and of course it is a pain, especially because the command history is also different across the regular git bash.

Other answers in stackoverflow helped only to arrive at my above workaround. If I do

ssh-add ~/.ssh/mygithubkey

directly in my git bash, it says could not connect to ssh-agent. If I do

ssh-agent ssh-add ~/.ssh/mygithubkey
git pull
ssh -vT git@github.com

directly in my git bash, it says permission denied, it seems ssh-add did not really add the key permanently! And the added key is not offered while looking at the debug messages in verbose mode.

Is there anyway to permanently add a list of ssh keys to offer, when sshing into github? Im mostly a windows user today, so please be verbose in the answer.

Zasz
  • 12,330
  • 9
  • 43
  • 63
  • Why do you need multiple keys? One key should be all you ever need. – Tekkub Aug 29 '11 at 07:52
  • You are right, i can manage with just one key, but just as an academic question, could folks here attempt an answer?? – Zasz Aug 30 '11 at 10:02
  • 1
    It's possible, but a big pain in the ass and really not worth doing: http://help.github.com/multiple-ssh-keys/ – Tekkub Aug 31 '11 at 01:20

1 Answers1

11

I'd suggest to use a ~/.ssh/config file similar to this answer. Something like:

Host github1
    User git
    Hostname github.com
    IdentityFile ~/.ssh/mygithubkey

Host github2
    User git
    Hostname github.com
    IdentityFile ~/.ssh/myothergithubkey

That way you could easily switch keys by typing either ssh github1 or ssh github2 to connect.

Community
  • 1
  • 1
sschuberth
  • 28,386
  • 6
  • 101
  • 146
  • 1
    Where would that be on Windows? – CMCDragonkai Nov 11 '13 at 16:42
  • 5
    The tilde (`~`) is a placeholder for the current user's home directory, i.e. what the combination of `%HOMEDRIVE%%HOMEPATH%` on Windows points to. Starting with Windows Vista this would be something like `C:\Users\`, so the config file would be at `C:\Users\\.ssh\config`. – sschuberth Nov 11 '13 at 20:26