1. 程式人生 > >git從本地新增到github遠端庫失敗的解決方法

git從本地新增到github遠端庫失敗的解決方法

問題描述:

最近在學git以及github,但是遇到一個問題就是與github.com連線不通

[email protected]:/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

但是,卻沒有出現教程中的測試結果,依然是

[email protected]:/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代理修復這個錯誤

具體操作為:

[email protected]:/home/liuxinux# eval "$(ssh-agent -s)" Agent pid 3220 [email protected]:/home/liuxinux# ssh-add Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

然後在進行測試

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

竟然success了!

但是!┗|`O′|┛

當我滿心歡喜推送時

[email protected]:/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 看見沒有,最後有強制推送唉,那就強制推送吧!果然

[email protected]:/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 版權宣告:本文為博主原創文章,轉載請附上博文連結!