Windows上Github公私鑰建立連接問題的一種解決方案

作為Github的一個新手,你可能會遇到跟我一樣的狀況,其中過程就不說了,詳細可以看我還活著:學(xué)習(xí)廖雪峰的Git教程,這里的話就說說配公私鑰連接github的問題,實際上就下面兩步。

    C:\Users\Linger\learnGit>ssh -vT git@github.com
    OpenSSH_7.1p2, OpenSSL 1.0.2g  1 Mar 2016
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Connecting to github.com [192.30.253.112] port 22.
    debug1: Connection established.
    debug1: identity file /c/Users/Linger/.ssh/id_rsa type 1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/Linger/.ssh/id_rsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/Linger/.ssh/id_dsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/Linger/.ssh/id_dsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/Linger/.ssh/id_ecdsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/Linger/.ssh/id_ecdsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/Linger/.ssh/id_ed25519 type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/Linger/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_7.1
    debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
    debug1: no match: libssh-0.7.0
    debug1: Authenticating to github.com:22 as 'git'
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
    debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
    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.
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: SSH2_MSG_SERVICE_REQUEST sent
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /c/Users/Linger/.ssh/id_rsa
    debug1: Server accepts key: pkalg ssh-rsa blen 279
    debug1: Authentication succeeded (publickey).
    Authenticated to github.com ([192.30.253.112]:22).
    debug1: channel 0: new [client-session]
    debug1: Entering interactive session.
    debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    Hi ***************! You've successfully authenticated, but GitHub does not provide shell access.
    debug1: channel 0: free: client-session, nchannels 1
    Transferred: sent 3100, received 1796 bytes, in 1.1 seconds
    Bytes per second: sent 2916.4, received 1689.6
    debug1: Exit status 1

上面中間空出來的說明第二步,這里是正確完成的??吹紿i ***************! You've successfully authenticated就說明正確連接,在github上也看得到公鑰被使用過的記錄。
這里我必須解釋一下我犯的錯誤,就是第二步直接按回車,然后去找其他方法。實際上回車的默認選項是NO,而我們是要繼續(xù)連接才行,原理為什么第一次硬是找不到我也不清楚。
幾個我糾結(jié)的問題說一下:

  1. /c/Users/這種目錄路語法有沒有問題。這種一般我在linux看到,但是windows上是用C:\Users這樣的寫法的,你可以發(fā)現(xiàn)無法cd /c/Users,我一開始以為是這個問題,后面驗證了發(fā)現(xiàn)是有這樣的語法的,只是可能windows的cd不支持,你用ls /c/Users是找得到的。
  • 因為默認是驗證~/.ssh/id_rsa,如果你確實覺得目錄語法有問題,實際上你可以在ssh后加上-i選項來指定你的文件,如ssh -vT git@github.com -i D:\id_rsa,然后你會發(fā)現(xiàn)debug出來的目錄格式就是你的格式
  • -v是debug選項,當然你可以不加,但是作為程序員,你有責(zé)任和義務(wù)知道它到底做了什么,特別是出錯的時候

總結(jié):

嘗試在是否嘗試連接后加個yes而不是直接回車,回車默認不一定就是yes,B了狗了,默認是NO又不說一聲!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容