利用SSH将本地仓库文件推送至远程仓库(GitHub)

使用以下命令创建公钥:

shell 复制代码
ssh-keygen -t rsa -C "xxx@xx.com"

填写自己的邮箱,无需设置密码,一路回车即可。

使用以下命令查看 SSH 秘钥:

shell 复制代码
cd ~/.ssh

.ssh 目录存放在用户主目录下,里面存放了 id_rsaid_rsa.pub 两个文件,它们是 SSH key 的秘钥对。id_rsa 是私钥,不能轻易泄露, id_rsa.pub 是公钥,可以让他人知道。

使用以下命令查看公钥内容:

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

复制公钥,粘贴到自己的 GitHub 上。具体来说,打开 GitHub 设置中的 SSH and GPG keys 选项,然后添加新的 SSH key,将公钥的内容粘贴进去即可。

推送文件:

shell 复制代码
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:user_name/project_name.git
git push -u origin main
相关推荐
IMPYLH7 小时前
Linux 的 pinky 命令
linux·运维·服务器·bash
shandianchengzi7 小时前
【记录】Copilot|Github Copilot重新学生认证通过方法(2025年7月,包括2FA和认证材料、Why are you not on campus)
github·copilot
K1ne_7 小时前
2026 最新版|学生认证白嫖 GitHub Copilot Pro 保姆级教程
github·copilot
cs.shunzhang7 小时前
GitHub 教育认证通过后如何领取 Copilot Pro
github·copilot
程序员柒叔8 小时前
OpenCode 踩坑记:GitHub Copilot 按次计费?我的账单为何暴涨 3 倍!
github·copilot·claude code·opencode
刚刚觉醒的小菜鸡8 小时前
copilot学生认证2026-github copilot学生认证(手把手教会)
github·copilot
HelloWorld_SDK8 小时前
Docker安装OpenClaw
运维·docker·容器·openclaw
徐小夕8 小时前
我花一天时间Vibe Coding的开源AI工具,一键检测你的电脑能跑哪些AI大模型
前端·javascript·github
REDcker8 小时前
Linux iptables 与 Netfilter:原理、路径与运维要点
linux·运维·服务器
KKKlucifer10 小时前
零信任融合实践:国内堡垒机如何落地动态权限与实时阻断
运维