Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an SSH-key permanently in msysgit windows

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 [email protected] 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 [email protected]: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 [email protected]

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.

like image 236
Zasz Avatar asked Aug 29 '11 06:08

Zasz


1 Answers

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.

like image 194
sschuberth Avatar answered Sep 23 '22 15:09

sschuberth