github连接失败Host key verification failed.解决方案

问题描述

之前一直用的gitee协同协作,然后再最近一次云计算项目中团队使用的是github进行协作,但是按照常规步骤再GitHub上配置了ssh密钥后,却依然显示连接失败,无法推送和拉取代码,克隆仓库也是报错拒绝。具体报错信息如下:

bash 复制代码
Offending RSA key in /c/Users/32804/.ssh/known_hosts:1
RSA host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

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

原因分析

一开始我一直是觉得问题可能是出在了gitee和github的兼容问题上,可能两者的密钥被我的不经意间操作哪一个被覆盖了,也是在这个方向找网上的资料debug,但是都没有用。后面当我具体分析报错日志后,终于得出了解决方案:这个错误通常是由于连接 GitHub 时发现与之前保存在你本地系统中的 GitHub 主机密钥(host key)不匹配引起的。

解决方案

可以按照如下步骤解决问题:

  • step1:清除known_host文件中的旧密钥
    打开你的终端,执行以下命令清除 known_hosts 文件中与 GitHub 相关的旧密钥:
bash 复制代码
ssh-keygen -R github.com
  • step2:重新连接 GitHub
    重新连接 GitHub 并将其新密钥添加到 known_hosts 文件中。你可以通过执行以下命令连接 GitHub:
bash 复制代码
ssh -T git@github.com

然后就解决啦!

相关推荐
ll5776443321 小时前
使用PyTorch实现自定义损失函数以FocalLoss为例的详细教程
git
李少兄2 小时前
Git 用户名与邮箱配置指南
git
puyaCheer2 小时前
Android 13 启动的时候会显示一下logo,很不友好
android·gitee
Blue啊3 小时前
code Merge(qcc)
git·gitlab
逛逛GitHub4 小时前
推荐 3 个 GitHub 开源项目,让你的 Claude Code 与众不同。
github
whysqwhw6 小时前
KSP 全面讲解
github
whysqwhw6 小时前
KotlinPoet 详解
github
洛小豆8 小时前
Git打标签仓库看不到?她说:豆子,你又忘了加 --tags!
git·后端·github
不老刘8 小时前
GitHub Spec-Kit:AI 时代的规范驱动开发工具
人工智能·github·spec-kit
piggy侠8 小时前
【GitHub每日速递 251016】23k star,Daytona:90ms内极速运行AI代码,安全弹性基础设施来袭!
算法·github