V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
DaCong
V2EX  ›  git

ssh -T [email protected] 出现 ssh_exchange_identification: Connection closed by remote host 的错误

  •  
  •   DaCong · 2016-07-06 07:34:03 +08:00 · 18865 次点击
    这是一个创建于 2823 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本人是在 win10 系统下使用在 https://git-scm.com/download/win 下载的 git 命令行。 在使用 ssh -vT [email protected] 后,输出如下:

    $ ssh [email protected] -vT
    OpenSSH_7.1p2, OpenSSL 1.0.2h  3 May 2016
    debug1: Reading configuration data /c/Users/DaCong/.ssh/config
    debug1: /c/Users/DaCong/.ssh/config line 1: Applying options for github.com
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Connecting to ssh.github.com [182.239.95.136] port 443.
    debug1: Connection established.
    debug1: identity file /c/Users/DaCong/.ssh/id_rsa type 1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_rsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_dsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_dsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_ecdsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_ecdsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_ed25519 type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_7.1
    ssh_exchange_identification: Connection closed by remote host
    

    从 debug 的结果来看,应该是没有找到 key 文件,可是,我在 ~/.ssh/ 下执行 ls -la 之后,输出如下:

    total 34
    drwxr-xr-x 1 DaCong 197609    0 7 月   5 09:47 ./
    drwxr-xr-x 1 DaCong 197609    0 7 月   5 23:10 ../
    -rw-r--r-- 1 DaCong 197609   53 7 月   5 08:43 config
    -rw-r--r-- 1 DaCong 197609 1679 7 月   5 09:19 id_rsa
    -rw-r--r-- 1 DaCong 197609  392 7 月   5 09:19 id_rsa.pub
    
    

    应该说我是有密钥文件的,而且也有读写权限,为什么就成了找不到 key 了呢? 因为这个问题,我提交文件的时候用的是 https , clone 也是,每次更新 hexo 博客都要输入密码,非常麻烦。 还有,我已经在 github 中提交了 id_rsa.pub 。 我已经在 google 上搜索过了,相似的问题的解决方案并没有起作用,所以来 V2EX 提问,希望能够解决问题。

    第 1 条附言  ·  2016-07-06 09:29:48 +08:00

    说明一下,贴出config文件:

    Host github.com
      Hostname ssh.github.com
      Port 443
    

    如果不写这个config,返回的结果是这样的

    $ ssh -vT [email protected]
    OpenSSH_7.1p2, OpenSSL 1.0.2h  3 May 2016
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Connecting to github.com [182.239.95.136] port 22.
    debug1: Connection established.
    debug1: identity file /c/Users/DaCong/.ssh/id_rsa type 1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_rsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_dsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_dsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_ecdsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_ecdsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_ed25519 type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/DaCong/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_7.1
    ssh_exchange_identification: read: Connection reset by peer
    

    因此,我是在参考了 https://help.github.com/articles/using-ssh-over-the-https-port/ 后,加入了config @aec4d @Citrus @xing393939

    17 条回复    2020-01-20 22:12:50 +08:00
    xing393939
        1
    xing393939  
       2016-07-06 07:40:56 +08:00 via iPhone   ❤️ 1
    看下你 windows 的 c 盘有 c:/Users/DaCong/.ssh/吗,另外 你那 debug 信息好像还在找 https 的证书?
    aec4d
        2
    aec4d  
       2016-07-06 08:02:01 +08:00   ❤️ 1
    并不是没有找到该文件 identity file /c/Users/DaCong/.ssh/id_rsa type 1
    你可以执行 ssh -T [email protected] -vvv 查看更详细的信息
    同时贴出你的 config 文件看看
    最后你连接的是 ssh.github.com:443 这果断是不科学的
    aec4d
        3
    aec4d  
       2016-07-06 08:13:14 +08:00   ❤️ 1
    另外 你上面显示连接的 ip 是中国移动的 ip.......
    如果本来就被中间人 连不上也是情理之中的了
    Citrus
        4
    Citrus  
       2016-07-06 08:36:50 +08:00 via iPhone   ❤️ 1
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Connecting to ssh.github.com [182.239.95.136] port 443.

    你在逗我么?写了配置强制 ssh 去连 HTTPS 端口???
    DaCong
        5
    DaCong  
    OP
       2016-07-06 09:30:32 +08:00
    @xing393939
    @aec4d
    @Citrus
    感谢回复,请看附言,谢谢
    cielpy
        6
    cielpy  
       2016-07-06 09:43:37 +08:00   ❤️ 1
    @Citrus 这样写有什么问题吗
    yangtukun1412
        7
    yangtukun1412  
       2016-07-06 09:44:24 +08:00 via Android   ❤️ 1
    config 里加上 IdentityFile ~/.ssh/id_rsa ,另外文件权限应该要 600 才可以。
    aec4d
        8
    aec4d  
       2016-07-06 09:54:20 +08:00   ❤️ 1
    @DaCong 是因为你用的网络被中间人了 你可以查那个 IP 是移动的不是 github 的 当然会握手协商失败 挂代理吧:D
    或者你试一下添加 hosts
    192.30.253.112 github.com
    aec4d
        9
    aec4d  
       2016-07-06 09:56:00 +08:00   ❤️ 1
    ssh -T [email protected] -vvv 直接这样测试
    lonelinsky
        10
    lonelinsky  
       2016-07-06 10:07:59 +08:00   ❤️ 1
    ~/.ssh/id_rsa 的权限太开放了吧,改为 400 或者 600 试试…
    Citrus
        11
    Citrus  
       2016-07-06 10:15:00 +08:00   ❤️ 1
    @DaCong
    @cielpy 我的错,没注意 GitHub 支持 SSH over HTTPS ,这样写没问题。
    不过
    @DaCong 你的网络明显是被劫持了, 182.239.95.136 并不是 GitHub 的 IP ,而是香港中国移动的反代服务器,所以导致这个问题。其实没有特殊情况的话,没必要 SSH over HTTPS ,直接用 SSH 不就可以了?
    raysonx
        12
    raysonx  
       2016-07-06 10:15:57 +08:00   ❤️ 1
    @aec4d 正解。
    根据楼主的日志, github.com 解析到了 182.239.95.136 ,这个 IP 是中国移动的 SNI 缓存服务器:

    IPIP.net 数据
    您输入的 IP: 182.239.95.136
    中国香港 移动

    结论就是,楼主的运营商(移动)使用 DNS 劫持将 github.com 劫持到了移动的缓存服务器。
    skydiver
        13
    skydiver  
       2016-07-06 10:16:32 +08:00 via Android   ❤️ 1
    key 权限必须是 600
    DaCong
        14
    DaCong  
    OP
       2016-07-06 10:17:58 +08:00
    @aec4d edit the hosts file can work! Thx
    lslqtz
        15
    lslqtz  
       2016-07-06 14:43:05 +08:00 via iPhone   ❤️ 1
    又得到了个新缓存服务器。
    tomorrowin
        16
    tomorrowin  
       2018-03-18 22:26:08 +08:00
    THIS post helped me out !!!!thank you sooooooooooo much!!!!!
    shuirong1997
        17
    shuirong1997  
       2020-01-20 22:12:50 +08:00
    help me too, thank you, guys.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5606 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 01:40 · PVG 09:40 · LAX 18:40 · JFK 21:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.