简体   繁体   中英

Git: Permission denied (publickey). fatal: Could not read from remote repository

I've never cloned a private GitHub repository. So I followed GitHub's guide but it's still rejecting me. I have a Red Hat linux server on AWS. I did the following:

  1. Ran ssh-keygen -t rsa -b 4096 -C "< my github email address >" .
  2. Ran eval "$(ssh-agent -s)" .
  3. Ran ssh-add ~/.ssh/id_rsa .
  4. Ran cat ~/.ssh/id_rsa.pub (to get the value of the key).
  5. Added output of step 4 into here: https://github.com/settings/keys .
  6. Ran ssh -T git@github.com and it outputted this:

    Hi AskYous! You've successfully authenticated, but GitHub does not provide shell access.

  7. Ran sudo git clone git@github.com:AskYous/google-code-challange.git (a private repository I own). This is when I got the following error:

    Cloning into 'google-code-challange'... Permission denied (publickey). fatal: Could not read from remote repository.

    Please make sure you have the correct access rights and the repository exists.

  8. I checked GitHub and it acknowledges that the key has been used: 在此处输入图片说明

The problem was, and I don't know how this happened, is that the private key changed so this new key was not stored on GitHub. It changed somehow. Perhaps I ran the generation process twice.

Just want to help anyone who's experiencing this issue as I spent a while trying to resolve. Make sure the key pairs ownership owned by buildkite-agent

-rw-r--r--. 1 buildkite-agent buildkite-agent 749 Jul 27 13:34 id_rsa.pub -rw-------. 1 buildkite-agent buildkite-agent 3243 Jul 27 13:34 id_rsa

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM