git bash 使用ssh push 时报错(fatal: Could not read from remote repository.)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/imilano/article/details/82151670

问题

在看耗子叔的博客,重新梳理自己的一些学习路线。于是,想在自己的GitHub上记录自己一路的学习路程。说干就干,一路git init/add/commit/push,本以为妥了,没曾想,给我报这个错:

\302\226[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

这里写图片描述

很扎心。这才想起来,之前在git clone 的时候也出现过这样的问题。没得法,求助于万能的谷歌。

解决过程

一番google,在stackoverflow 看到这么一个问题
这不正是我想要的吗!看了第一个答案,不是我的菜(最后发现人家一眼就看出问题出在哪里了)。试了第二个答案,没错,能解决:就是在 git remote add 的时候使用HTTP,而不是使用git。没错,问题是解决了,但是为什么使用git就不行呢?

碰巧往下一瞥,
这里写图片描述看到这么一句话:
This answer changed the mechanism from ssh to https. It is not solving the original problem by using ssh to access the repository. I wonder how this can keep getting upvoted as a good answer to the question. The other answers down below are solving it properly.大意就是,从git换成https并没有从根本上解决问题,这位老哥想不通为啥这样的答案竟然被顶到了第二的位置。

深深佩服这些老外深究到底的精神。于是我开始再次寻找根本的解决方法,继续往下看,看到第三个正是我找的。试了一下,果然有问题,当我ssh-add -l查看自己已经添加的秘钥时,发现报错:

Could not open a connection to your authentication agent.

于是再次开始了google。

终于在这里找到了解决办法。取了个巧,尝试了第二个答案,完美解决。

解决

好的,这就是我的解决方案:

git remote rm origin

# 进入你的.ssh文件夹
eval $(ssh-agent)

# 然后
ssh-add id_rsa

# 然后 
ssh-add -l 

# 如果你输出了一串rsa秘钥,那么问题就解决啦

猜你喜欢

转载自blog.csdn.net/imilano/article/details/82151670