git从本地添加到github远程库失败的解决方法

问题描述:

最近在学git以及github,但是遇到一个问题就是与github.com连接不通

root@liuxin-PC:/home/liuxinux# ssh -T [email protected]
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).

当时是按照廖雪峰的教程做的,无论怎么样都不通。

解决思路:

解决问题嘛,首先想到的是度娘了,然后就在网上搜

The authenticity of host 'github.com (192.30.253.112)' can't be established.

这句报错信息。

找到了一篇关于这个问题的解决方法:点击打开链接 http://www.cnblogs.com/honeybusybee/p/5534894.html

文中提到的在知乎中找到的解决方法为

如果你曾经出现过这种问题,我有一个解决方案
首先,清除所有的key-pair
ssh-add -D
rm -r ~/.ssh
删除你在github中的public-key


重新生成ssh密钥对
ssh-keygen -t rsa -C "[email protected]"
chmod 0700 ~/.ssh
chmod 0600 ~/.ssh/id_rsa*


接下来正常操作
在github上添加公钥public-key:
1、首先在你的终端运行 xclip -sel c ~/.ssh/id_rsa.pub将公钥内容复制到剪切板
2、在github上添加公钥时,直接复制即可
3、保存


测试:
在终端 ssh -T [email protected]
成功,出现下面信息
Hi 1056739724! You've successfully authenticated, but GitHub does not provide shell access

但是,却没有出现教程中的测试结果,依然是

root@liuxin-PC:/home/liuxinux# ssh -T [email protected]
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).

于是我就疯了......

然而,但是

我发现了上面的教程中还有一句话:

第二次,又出现问题:


Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).


这时是用这个答案解决的点击打开链接
https://help.github.com/articles/error-agent-admitted-failure-to-sign/

虽然这句话和我的问题并不是十分相符,然而,我还是决定要死马当做活马医,先试试再说。

这个连接是英文教程,并且是github的官方help,看来解决问题还是直接找官方教程靠谱。

而且,这个教程中的问题描述其实也并不是很符合我的问题,but, whatever!

教程中的解决方式是:通过加载你的钥匙到您的SSH代理修复这个错误

具体操作为:

root@liuxin-PC:/home/liuxinux# eval "$(ssh-agent -s)"
Agent pid 3220
root@liuxin-PC:/home/liuxinux# ssh-add
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

然后在进行测试

root@liuxin-PC:/home/liuxinux# ssh -T [email protected]
Hi liuxinux! You've successfully authenticated, but GitHub does not provide shell access.

竟然success了!

但是!┗|`O′|┛

当我满心欢喜推送时

root@liuxin-PC:/home/liuxinux# git push -u origin master
To [email protected]:liuxinux/learngit.git
 ! [rejected]        master -> master (fetch first)
error: 无法推送一些引用到 '[email protected]:liuxinux/learngit.git'
提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外
提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
提示:(如 'git pull ...')。
提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。

一万匹澳洲特产小羊驼奔驰而过啊

但是,如果你跟我一样细心的话(嘿嘿...),你会发现,这个提示好像在哪里见过,然后我就往之前的那个教程中找,发现最后有

5、提交至github仓库

git push -u origin master
1
2
3
4
5
6
7
8
    
//报错了:
提示:更新被拒绝,因为远程版本库包含您本地尚不存在的提交。这通常是因为另外
提示:一个版本库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
提示:(如 'git pull ...')。
提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。
 
//强制推送
git push origin +master
看见没有,最后有强制推送唉,那就强制推送吧!果然

root@liuxin-PC:/home/liuxinux# git push origin +master
对象计数中: 6, 完成.
Delta compression using up to 4 threads.
压缩对象中: 100% (2/2), 完成.
写入对象中: 100% (6/6), 489 bytes | 0 bytes/s, 完成.
Total 6 (delta 0), reused 0 (delta 0)
To [email protected]:liuxinux/learngit.git
 + 113809e...97a5e90 master -> master (forced update)

成功了!去github中查看也找到了推送的文件!

(o゜▽゜)o☆[BINGO!]

问题解决!

然而我还是要说但是

因为我是个刚开始学习的小白,这个问题站在前人的肩膀上解决了,不过出现这个问题的原因是什么,以及为什么要这么解决不是很清楚,理解还是不够透彻!

所以,在以后的学习过程中,还要多加留心此类问题,以及向大神们请教学习。


---------------------
作者:柳歆
来源:CSDN
原文:https://blog.csdn.net/laner415/article/details/52966890?utm_source=copy
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/aa19891204/article/details/83062614