GitHub Error: Key already in use

后端 未结 7 1948
逝去的感伤
逝去的感伤 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:37

    you can use the same ssh key for different github repositories but cannot use the same ssh key for many repositories (i.e,same repository from different logins or from forked) as github will not allow same deploy key more than once for a repository

    You can create a different key in your machine without disturbing your existing keys like:ssh-keygen -t rsa -C "your_email@example.com"
    Now provide your file name to identify your key for the repository

    Enter file in which to save the key (/home/demo/.ssh/id_rsa):/home/demo/.ssh/id_rsa_mykey<br>
    

    See https://developer.github.com/guides/managing-deploy-keys/#deploy-keys for details.

    0 讨论(0)
  • 2021-01-30 03:40

    John commented that it didn't work for him.

    Perhaps the step you're missing is you need to alter your .git/config remote url to point to git@github-personal/<reponame>.git etc.. rather than the usual git@github.com/<reponame>.git

    0 讨论(0)
  • 2021-01-30 03:50

    You can create one more key pair, say id_rsa_personal.pub, and add it to the Github account.

    Next, create/edit the .ssh/config file.

    # Default GitHub
    Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa
    
    Host github-public
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_public
    
    Host github-personal
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_personal
    

    The above file will help you to use more than one Github account. For background info, refer to the answers to this question.

    Next, you will need to alter your .git/config remote url to point to:

    git@github-personal:<gh_username>/<gh_reponame>.git

    Rather than the usual:

    git@github.com:<gh_username>/<gh_reponame>.git

    0 讨论(0)
  • 2021-01-30 03:51

    The key could be already in use on other github projects as deploy key, that's a bit tricky to find but run:

    ssh -T -ai ~/.ssh/id_rsa git@github.com

    to find the used key, delete it and then readd it again in the right user/repo. that was very useful for me

    from: https://help.github.com/articles/error-key-already-in-use/#finding-where-the-key-has-been-used


    edit: as pointed out by @mikhail-morgunov, this doesn't works all the time, you should really use this snippet only if the default id_rsa SSH private key is your github's default one

    this is a snippet where the key name has been extracted:

    ssh -T -ai ~/.ssh/KEY_NAME git@github.com

    change KEY_NAME with the name of your SSH private key and you will be good to go

    0 讨论(0)
  • 2021-01-30 03:52

    You probably just need to change the name of your key.

    ssh-keygen -t rsa -b 4096 -C "<email>"
    

    Then it will ask to enter the file name, make sure that you enter the path name which does not exist on your system. Usually, "id_rsa" file name is created by default on MAC. Just change the name and then use following command to copy

    pbcopy < {Path where SSH-Keygen is stored}
    

    That's it. You can simply paste this keygen (copied from above command on the clipboard) in GitHub and use that without any problem.

    0 讨论(0)
  • 2021-01-30 03:52

    This works for me,

    1. Generate the SSH keys using ssh-keygen. Let's say the key is in ~/.ssh/id_rsa_foo
    2. Now, $ cat ~/.ssh/id_rsa_foo.pub and paste it on your GitHub keys.
    3. You can use GIT_SSH_COMMAND environment variable to achieve what you want.
      Do $ GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa_foo' git push origin master. Check your Github repo for the magic. Cheers!
    0 讨论(0)
提交回复
热议问题