Windows上Github公私钥建立连接问题的一种解决方案

作为Github的一个新手,你可能会遇到跟我一样的状况,其中过程就不说了,详细可以看我还活着:学习廖雪峰的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

上面中间空出来的说明第二步,这里是正确完成的。看到Hi ***************! You’ve successfully authenticated就说明正确连接,在github上也看得到公钥被使用过的记录。
这里我必须解释一下我犯的错误,就是第二步直接按回车,然后去找其他方法。实际上回车的默认选项是NO,而我们是要继续连接才行,原理为什么第一次硬是找不到我也不清楚。
几个我纠结的问题说一下:

  1. /c/Users/这种目录路语法有没有问题。这种一般我在linux看到,但是windows上是用C:\Users这样的写法的,你可以发现无法cd /c/Users,我一开始以为是这个问题,后面验证了发现是有这样的语法的,只是可能windows的cd不支持,你用ls /c/Users是找得到的。
  • 因为默认是验证~/.ssh/id_rsa,如果你确实觉得目录语法有问题,实际上你可以在ssh后加上-i选项来指定你的文件,如ssh -vT git@github.com -i D:\id_rsa,然后你会发现debug出来的目录格式就是你的格式
  • -v是debug选项,当然你可以不加,但是作为程序员,你有责任和义务知道它到底做了什么,特别是出错的时候

总结:

尝试在是否尝试连接后加个yes而不是直接回车,回车默认不一定就是yes,B了狗了,默认是NO又不说一声!

    原文作者:QingLinger
    原文地址: https://www.jianshu.com/p/3cd7883f0b8b
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞