Github报错:Kex_exchange_identification: Connection closed by remote host

1. 背景介绍

Github提交或者拉取代码时,报错如下:

Kex_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

SSH Key已经设置并且同步。

# ssh -T git@github.com
kex_exchange_identification: Connection closed by remote host

2. 排查和解决方案

这个错误表明 SSH 连接被远程主机关闭,可能的原因包括:

  • 网络问题:确保你的网络连接正常,没有被防火墙或代理阻挡。尝试使用其他网络连接来排除网络问题。
  • SSH 配置问题:检查 SSH 配置文件(通常在 ~/.ssh/config 中)是否正确。如果文件不存在,你可以尝试创建一个基本配置文件:
Host github.com
  User git
  Hostname github.com
  IdentityFile ~/.ssh/id_rsa

  • SSH 密钥问题:确保你的 SSH 密钥正确配置,并且已经将公钥添加到 GitHub 账户中。你可以尝试重新生成 SSH 密钥并添加:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

然后将 ~/.ssh/id_rsa.pub 文件的内容添加到 GitHub 的 SSH 密钥中。

  • GitHub 服务器问题:GitHub 服务器可能暂时出现问题。你可以访问 GitHub 状态页面 检查是否有服务中断。
  • SSH 客户端问题:确保你的 SSH 客户端是最新版本,尝试升级 SSH 客户端或重新安装。
  • 检查 GitHub 端口:确保你的网络没有阻挡 SSH 端口(通常是端口 22)。有时公司或组织的网络会限制这些端口。
  • 使用 HTTPS:如果 SSH 无法解决问题,可以尝试使用 HTTPS 克隆仓库:
git clone https://github.com/JMoonr/LATR.git
  • 替代端口,端口 443:这通常用于绕过防火墙或代理限制,因为端口 443 是 HTTPS 的标准端口。可以尝试使用这个端口来连接 GitHub。
Host github.com
  HostName ssh.github.com
  User git
  Port 443
  IdentityFile ~/.ssh/id_rsa

如果上述都不行的话,大概率是开了VPN。关闭VPN,过一段时间就正常了。
在这里插入图片描述

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-21 12:02:05       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-21 12:02:05       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-21 12:02:05       45 阅读
  4. Python语言-面向对象

    2024-07-21 12:02:05       55 阅读

热门阅读

  1. c++应用网络编程之四Linux常用的网络IO模型

    2024-07-21 12:02:05       18 阅读
  2. 【NLP】关于参数do_sample的解释

    2024-07-21 12:02:05       15 阅读
  3. DAY17-二叉树

    2024-07-21 12:02:05       19 阅读
  4. 【Linux】vim编辑器使用详解

    2024-07-21 12:02:05       19 阅读
  5. 用数组简单构成队列C++写法

    2024-07-21 12:02:05       14 阅读
  6. 【无标题】

    2024-07-21 12:02:05       19 阅读
  7. 图像细节增强:锐化处理的实践与分析

    2024-07-21 12:02:05       15 阅读
  8. 堆和栈以及垃圾回收在C#中的使用

    2024-07-21 12:02:05       18 阅读
  9. 我的创作一周年纪念日

    2024-07-21 12:02:05       18 阅读