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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With