问题
I've cloned a private repo, forked it and made som changes into a feature branch. When I try to push these changes into the repo i get the following message:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I've tried to delete the git credentials from my windows computer controlpanel>credentials but it's still showing me the same error.
Is there any chance that I have to log in and out from my terminal to git? If that would be the case, how do I do that?
I've also tried to push with git push --set-upstream origin but it's just showing me the same error.
Have anyone of you seen this before?
Thanks beforehand, Erik
回答1:
"Help, I keep getting a 'Permission Denied (publickey)' error when I push!"
This means, on your local machine, you haven't made any SSH keys. Not to worry. Here's how to fix:
- Open git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. Pro Tip: You can use any *nix based command prompt (but not the default Windows Command Prompt!)
- Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users[YOUR-USER-NAME].ssh\ on Windows)
- Within the .ssh folder, there should be these two files: id_rsa and id_rsa.pub. These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Type ls to see a directory listing. If those two files don't show up, proceed to the next step. NOTE: Your SSH keys must be named id_rsa and id_rsa.pub in order for Git, GitHub, and BitBucket to recognize them by default.
- To create the SSH keys, type ssh-keygen -t rsa -C "your_email@example.com". This will create both id_rsa and id_rsa.pub files.
- Now, go and open id_rsa.pub in your favorite text editor (you can do this via Windows Explorer or the OSX Finder if you like, typing open . will open the folder).
- Copy the contents--exactly as it appears, with no extra spaces or lines--of id_rsa.pub and paste it into GitHub and/or BitBucket under the Account Settings > SSH Keys. NOTE: I like to give the SSH key a descriptive name, usually with the name of the workstation I'm on along with the date.
- Now that you've added your public key to Github and/or BitBucket, try to git push again and see if it works. It should!
More help available from GitHub on creating SSH Keys.
回答2:
This can be your ssh key is not authorised - Permission denied (publickey).
Solution 1
Check if GitHub protocols are not from ssh to https
check remote url
git remote -v`
Change remote url
git remote set-url origin https://URL
Solution 2
- Generate a SSH key on your computer
- Login to your GitHub account
- Add the newly generated SSH Key to your account through this link
- Try again to git clone the project.
if after setting ssh key it still fails you might require system restart
Solution 3
This is not a solution just work around for newbies to clone public repo without caring protocols
Use this example
git clone https://github.com/%REPOSITORYFOLDER%/%REPOSITORYNAME%.git
Instead of
git clone git@github.com:%REPOSITORYFOLDER%/%REPOSITORYNAME%.git
all these solutions are collected from different sources will update it if more solution found which works for such scenarios
来源:https://stackoverflow.com/questions/58429764/git-could-not-read-from-remote-repository