Permission denied (publickey). fatal: The remote end hung up unexpectedly

When I was learning git in the past two days, I created a library locally, and at the same time I also created a library on GitHub. Following Mr. Liao's tutorial step by step, I went to the push link and suddenly such an error occurred:

[zhangxiyu@localhost learngit] $ git push -u origin master 
Permission denied (publickey). 
fatal: The remote end hung up unexpectedly

Go to Baidu, CSDN, GitHub and other places to check and only get one answer, saying that the publickey is not bound to the remote GitHub, but this step has been done before, there is no way but to delete the public key on GitHub At the same time, rm -r ~/.sshdelete all the .ssh folders locally, regenerate ssh-keygen, and re-bind .ssh/id_rsa.pub to GitHub. As a result, also Nima can't do it. Or prompt the above error! woc! ! ! see hell. Then it fell into an infinite loop, looking for solutions everywhere, but the result was all "no public key bound".

Fortunately, there is no way to go. Today, I accidentally saw git push uploading code to gitlab, and it reported an error of 401/403 (or you need to enter a user name and password) This post, I suddenly thought of it, I seem to have encountered it before push yesterday. this problem:

[zhangxiyu@localhost learngit]$ git push -u github 
error: The requested URL returned error: 403 Forbidden while accessing 
https://github.com/zxy9527/zxy.git/info/refs

fatal: HTTP request failed

Then I looked up the problem on the Internet and somehow decided vi .git/config, and put the

[remote “github”] 
url = https://github.com/zxy9527/zxy.git 
fetch = +refs/heads/:refs/remotes/github/

changed to

[remote “github”] 
url = ssh://github.com/zxy9527/zxy.git 
fetch = +refs/heads/:refs/remotes/github/

Hi Da Puben, the 403 problem is gone, but what follows is an infinite Permission denied (publickey). . . That's the problem mentioned above.

  • Solution

In the .git/config file of the code, add the "username: password@" of the gitlab registration before the gitlab domain name of the url of [remote "origin"]

For example, my GitHub username is blx9527 and the password is blx123456 (of course not the real password~), so the .git/config file should be changed to:

[remote “github”] 
url = https://blx9527:[email protected]/zxy9527/zxy.git 
fetch = +refs/heads/:refs/remotes/github/

After changing, make sure your public key has been bound to GitHub (there are very detailed tutorials on the Internet), and you can push happily! !

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324938787&siteId=291194637