作為Github的一個(gè)新手氮采,你可能會(huì)遇到跟我一樣的狀況殷绍,其中過(guò)程就不說(shuō)了,詳細(xì)可以看我還活著:學(xué)習(xí)廖雪峰的Git教程鹊漠,這里的話就說(shuō)說(shuō)配公私鑰連接github的問(wèn)題篡帕,實(shí)際上就下面兩步殖侵。
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
上面中間空出來(lái)的說(shuō)明第二步,這里是正確完成的镰烧。看到Hi ***************! You've successfully authenticated就說(shuō)明正確連接楞陷,在github上也看得到公鑰被使用過(guò)的記錄怔鳖。
這里我必須解釋一下我犯的錯(cuò)誤,就是第二步直接按回車,然后去找其他方法固蛾。實(shí)際上回車的默認(rèn)選項(xiàng)是NO结执,而我們是要繼續(xù)連接才行,原理為什么第一次硬是找不到我也不清楚艾凯。
幾個(gè)我糾結(jié)的問(wèn)題說(shuō)一下:
- /c/Users/這種目錄路語(yǔ)法有沒(méi)有問(wèn)題献幔。這種一般我在linux看到,但是windows上是用C:\Users這樣的寫法的趾诗,你可以發(fā)現(xiàn)無(wú)法cd /c/Users蜡感,我一開(kāi)始以為是這個(gè)問(wèn)題,后面驗(yàn)證了發(fā)現(xiàn)是有這樣的語(yǔ)法的恃泪,只是可能windows的cd不支持郑兴,你用ls /c/Users是找得到的。
- 因?yàn)槟J(rèn)是驗(yàn)證~/.ssh/id_rsa贝乎,如果你確實(shí)覺(jué)得目錄語(yǔ)法有問(wèn)題情连,實(shí)際上你可以在ssh后加上-i選項(xiàng)來(lái)指定你的文件,如ssh -vT git@github.com -i D:\id_rsa览效,然后你會(huì)發(fā)現(xiàn)debug出來(lái)的目錄格式就是你的格式
- -v是debug選項(xiàng)却舀,當(dāng)然你可以不加,但是作為程序員锤灿,你有責(zé)任和義務(wù)知道它到底做了什么挽拔,特別是出錯(cuò)的時(shí)候
總結(jié):
嘗試在是否嘗試連接后加個(gè)yes而不是直接回車,回車默認(rèn)不一定就是yes衡招,B了狗了篱昔,默認(rèn)是NO又不說(shuō)一聲!