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

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

相关推荐
是毛毛吧8 小时前
边打游戏边学Python的5个开源项目
python·开源·github·开源软件·pygame
拽着尾巴的鱼儿10 小时前
工具篇:git 分支版本回退
git
无限进步_13 小时前
深入理解 C/C++ 内存管理:从内存布局到动态分配
c语言·c++·windows·git·算法·github·visual studio
java程序员一位17 小时前
从公司项目复制迁移到个人仓库
github
要加油哦~17 小时前
报错 | git 提交时,报错 .husky/commit-msg: line 4: npx: command not found | 仓库提交规范问题
git
Mr卜颛17 小时前
【Git】TortoiseGit(小乌龟)配置SSH和使用;Fork设置ssh key
git·ssh
_OP_CHEN19 小时前
【Git原理与使用】(二)Git 配置与基本操作全攻略:从配置到实战,新手也能轻松上手!
linux·运维·git·版本管理·企业级组件·git基本操作·git配置
安果移不动20 小时前
git Cherry-Pick合并分支上的某些commits-》Android studio
android·git·android studio
WYiQIU20 小时前
突破字节前端2-1⾯试: JS异步编程问题应答范式及进阶(视频教学及完整源码笔记)
开发语言·前端·javascript·vue.js·笔记·面试·github
Better Bench20 小时前
git与github协作开发的常用命令
git·github