ssh -T git@github.com 出现异常

上传代码到github 私有仓库

步骤

1. 生成 SSH Key(如果没有)

打开终端并运行:

bash

复制

复制代码
ssh-keygen -t ed25519 -C "your_email@example.com"
  • 按提示保存密钥文件和设置密码短语(可选)。
  • 默认位置是 ~/.ssh/id_ed25519
2. 添加 SSH Key 到 GitHub
  • 复制公钥内容:

    bash
    复制

    复制代码
    cat ~/.ssh/id_ed25519.pub
  • 登录 GitHub,进入个人设置。

  • 选择 "SSH and GPG keys",点击 "New SSH key"。

  • 粘贴公钥,添加标题,然后保存。

按照上面之下 测试 ssh -T -v git@github.com

出现:

复制代码

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

Someone could be eavesdropping on you right now (man-in-the-middle attack)!

It is also possible that a host key has just been changed.

The fingerprint for the RSA key sent by the remote host is

SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.

Please contact your system administrator.

Add correct host key in /Users/zhuchuanshun/.ssh/known_hosts to get rid of this message.

Offending RSA key in /Users/zhuchuanshun/.ssh/known_hosts:10

Host key for github.com has changed and you have requested strict checking.

解决:

出现这个问题是因为 GitHub 的主机密钥已更改,需要更新你的 known_hosts 文件。可以按照以下步骤解决:

解决步骤

  1. 备份当前 known_hosts 文件

    bash
    复制

    复制代码
    cp ~/.ssh/known_hosts ~/.ssh/known_hosts_backup
  2. 删除旧的 GitHub 主机密钥

    找到并删除与 GitHub 相关的行。可以使用 ssh-keygen 命令:

    bash
    复制

    复制代码
    ssh-keygen -R github.com
  3. 获取并添加新的 GitHub 主机密钥

    尝试连接 GitHub,这将自动添加新的主机密钥:

    bash
    复制

    复制代码
    ssh -T git@github.com

    你会看到提示,询问是否信任新的主机密钥,输入 yes

  4. 验证连接

    再次测试 SSH 连接:

    bash
    复制

    复制代码
    ssh -T git@github.com

    如果看到欢迎消息,说明问题已解决。

相关推荐
如意.7595 小时前
【Linux开发工具实战】Git、GDB与CGDB从入门到精通
linux·运维·git
用户91868612868710 小时前
Git 版本控制完全指南:从入门到精通
git
青晚舟10 小时前
AI 时代前端还要学 Docker & K8s 吗?我用一次真实部署经历说清楚
前端·github
星浩AI10 小时前
现在最需要被 PUA 的,其实是 AI
人工智能·后端·github
AI程序员12 小时前
Pi Monorepo 学习指南
github
简离12 小时前
Git 一次性清理已跟踪但应忽略文件
前端·git
Drone_xjw12 小时前
【环境搭建】Windows 10上使用Docker搭建本地Git仓库(Gitea)完整教程
windows·git·docker
疯狂成瘾者13 小时前
git学习目录
git·学习
曾几何时`14 小时前
Git——自用手册
git
Renhao-Wan16 小时前
基于 GitHub Actions 构建标准化 CI/CD 流水线——从手动部署到全自动化交付
ci/cd·自动化·github