问题
I'm trying to push a file to a git repo of a friend but errors on public key.
git push origin testbranch
Permission denied (publickey).
fatal: Could not read from remote repository.
Where and how do we define public / private keys?
git remote -v
returns:
origin git@github.com:Sesamzaad/NET.git (fetch)
origin git@github.com:Sesamzaad/NET.git (push)
Any help is appreciated.
回答1:
I was facing same problem, here is what I did that worked for me.
Use ssh instead of http. Remove origin if its http.
git remote rm origin
Add ssh url
git remote add origin git@github.com:<username>/<repo>.git
Generate ssh key inside .ssh/ folder. It will ask for path and passphrase where you can just press enter and proceed.
cd ~/.ssh
ssh-keygen
Copy the key. You can view your key using. If you hadn't specified a different path then this is the default one.
cat ~/.ssh/id_rsa.pub
Add this key to your github account. Next do
ssh -T git@github.com
You will get a welcome message in your console.
cd into to your project folder. git push -u origin master
now works!
回答2:
I just had to deal with this issue. @user3445140's answer helped me, but was much more than I needed to do.
- Get your public SSH key with
cat ~/.ssh/id_rsa.pub
- Copy the key, including the "ssh-rsa" but excluding your computer name at the end
- Go to https://github.com/settings/ssh
- Add your SSH key
回答3:
This worked for me.
first of all, remove current remote :
git remote rm origin
second, add remote through HTTPS but git@xxx :
git remote add origin https://github.com/Sesamzaad/NET.git
then push has worked for me :
git push origin master
回答4:
I am running Ubuntu 16.04
Removing the remote origin using
git remote rm origin
setting the http url using
git remote add origin https://github.com/<<Entire Path of the new Repo>>
git push origin master
Above steps successfully added code to repo.
回答5:
None of the above solutions worked for me. For context, I'm running ubuntu, and I had already gone through the ssh-key setup documentation. The fix for me was to run ssh-add
in the terminal. This fixed the issue.
Source: http://baptiste-wicht.com/posts/2010/07/tip-how-to-solve-agent-admitted-failure-to-sign-using-the-key-error.html
回答6:
I fixed it by readding the key to my ssh-agent. For some reasons it was gone.
回答7:
This worked for me. Simplest solution by far.
If you are using GitHub for Windows and getting this error, the problem might be that you are trying to run the command in the wrong shell or mode. If you are trying to do git push origin master
in the regular command prompt or PowerShell, this is the problem.
You need to do it in a git shell. Simply open Github for Windows, right click, and select "Open Shell Here". It looks like a regular PowerShell window, but it's not, which makes it really confusing for newbies to git, like myself.
I hope others find this useful.
回答8:
You probably have to add your public key to github. https://help.github.com/articles/generating-ssh-keys
Check this thread: GitHub: Permission denied (publickey). fatal: The remote end hung up unexpectedly
回答9:
The documentation from Github is really explanatory.
https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
I think you must do the lasts steps from the guide to proper configure your keys
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa
回答10:
Solution : you have to add you ssh key in your git-hub profile. Follow steps to solve this problem
- Right Click Folder you want to push in git
- Select git-bash here problem
- Write command ssh-keygen by this command your key is generated
- Copy the key from cmd or go to (C:/User/your_user/.ssh/)
- open id.rsa with notepad.
- Copy your key
- Now go to your git-hub profile
- Go to settings
- select SSH and Gpg keys
- select New ssh key option
- add window-key in the title
- Paste your key in the description part below title field
- Save
Now you are ready to push your folder
- Now go to folder you want to upload
- right click on the folder
- Select git bash here
- git init
- git add README.md
- git commit -m "first commit"
- git remote add origin https://github.com//
- git push -u origin master
Hope this will be Helpful for you
回答11:
If you already have your public key added to the GITHUB server there are other solutions that you can try.
In my case the GIT PUSH was failing from inside RUBYMINE but doing it from the Terminal window solved the problem.
For more solutions visit this page https://github.com/gitlabhq/gitlabhq/issues/4730
回答12:
In order to deploy to your friend's repo you need to add your public key to the repository's deploy keys.
Go to the repository, go to deploy keys, and add the id_rsa.pub (or whatever yours is named) to "deploy keys".
I believe adding the key to your own account only lets you write to repositories that your account created. If it was created by an organization you need to add the key to the repo's deploy keys.
https://developer.github.com/v3/guides/managing-deploy-keys/
回答13:
I faced the same problem.Ask your friend to add you as a collaborator by going to his repo settings and adding a new collaborator.
You will recieve an invite email ,accept it.Then you are good to go. Just make sure that you have added right remote.
回答14:
This error happened while using Ubuntu Bash on Windows.
I switched to standard windows cmd prompt, and it worked no error.
This is a workaround as it means you probably need to load the ssh private key in ubuntu environment if you want to use ubuntu.
回答15:
You need to fork the project to your own user repository.
Then add origin
:
git remote add upstream your-ssh-here
git fetch upstream
git branch --set-upstream-to=upstream/master master
来源:https://stackoverflow.com/questions/19660744/git-push-permission-denied-public-key