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
相关推荐
Lin_Aries_042120 分钟前
部署 GitLab 服务器
linux·运维·服务器·docker·gitlab·github
Dream_Ji1 小时前
Swift入门(二 - 基本运算符)
服务器·ssh·swift
真智AI3 小时前
[特殊字符] AI时代依然不可或缺:精通后端开发的10个GitHub宝藏仓库
人工智能·github·系统设计·后端开发·github资源·编码实践
Grassto11 小时前
免费的 CI/CD 服务,了解一下 GitHub Actions ?
ci/cd·github·github actions
DeepHacking12 小时前
GitHub代码推送指南
github
破坏的艺术12 小时前
GitHub Spec Kit:官方规格驱动开发工具包深度解析
github·vibe coding
weixin_4231961714 小时前
使用vscode的ssh功能连接远程服务器卡在Setting up SSH Host IP: Downloading VS Code Server的解决方案
服务器·vscode·ssh
京东零售技术1 天前
京东正式开源基于国产芯片自研的xLLM大模型推理引擎
github
寻月隐君1 天前
Rust 泛型编程基石:AsRef 和 AsMut 的核心作用与实战应用
后端·github
ayyyy____1 天前
把项目通过pycharm上传到github(两种方式)
ide·pycharm·github