github使用SSH推送

1️⃣ 确保 SSH Key 生成成功

运行:

复制代码
ls ~/.ssh/

看看是否有 id_rsaid_rsa.pub 这两个文件。如果没有,说明 SSH Key 还没有生成,需要重新生成:

复制代码
ssh-keygen -t rsa -b 4096 -C "你的GitHub邮箱"

然后一直按 回车 (默认存放在 ~/.ssh/id_rsa)。

2️⃣ 确保 SSH Key 已添加到 GitHub

运行:

复制代码
cat ~/.ssh/id_rsa.pub

复制 整个公钥内容 (从 ssh-rsa 开头,到结尾)。然后:

  1. 进入 GitHub SSH Keys 设置

  2. 点击 New SSH Key

  3. 粘贴公钥

  4. 保存


3️⃣ 让 SSH 识别你的 Key

运行:

复制代码
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa

然后重新测试 SSH 连接:

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

如果成功,你会看到:

Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.

4️⃣ 确保 GitHub 远程仓库 URL 使用 SSH

运行:

复制代码
git remote -v

如果看到的是 HTTPS:

origin https地址

https地址

那就需要改成 SSH:

复制代码
git remote set-url origin SSH地址

然后尝试:

复制代码
git push origin main
相关推荐
子兮曰6 小时前
async/await高级模式:async迭代器、错误边界与并发控制
前端·javascript·github
崔庆才丨静觅19 小时前
Claude Code GitHub Actions 使用教程
github·api·claude
砖厂小工2 天前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
程序员鱼皮2 天前
又一个新项目完结,我要出海了!
ai·github·开源项目
徐小夕2 天前
pxcharts-vue:一款专为 Vue3 打造的开源多维表格解决方案
前端·vue.js·github
Moment2 天前
想要长期陪伴你的助理?先从部署一个 OpenClaw 开始 😍😍😍
前端·后端·github
我叫黑大帅2 天前
前端如何利用 GitHub Actions 自动构建并发布到 GitHub Pages?
前端·面试·github
HelloGitHub2 天前
这个年轻的开源项目,想让每个人都能拥有自己的专业级 AI 智能体
开源·github·agent