GitHub Error: Key already in use

后端 未结 7 1949
逝去的感伤
逝去的感伤 2021-01-30 02:54

I have created two GitHub accounts. One for my work user and one for my personal self. I needed to do catch up on some work and as such cloned my work repo onto my personal PC

相关标签:
7条回答
  • 2021-01-30 03:57

    I've found a workaround that works for me:

    You cannot add the same SSH key to different accounts, and that is true for GitHub, BitBucket, etc. But you can use different SSH keys for each account. The only downside then is how to easily switch between them?

    I use ssh-agent and it can use multiple keys at the same time. I auto add them through .bashrc

    if [ -z "$SSH_AUTH_SOCK" ] ; then
      eval `ssh-agent -s`
      ssh-add ~/.ssh/id_rsa
      ssh-add ~/.ssh/id_rsa2
    fi
    

    This approach works regardless of which key is added in your GitHub account. I guess ssh-agent makes attempts with each key until it succeeds. And if you don't want to add all keys, you just comment out the relevant line in the .bashrc before starting a new shell.

    0 讨论(0)
提交回复
热议问题