MacOS 本地生成SSH key并关联Github

生成一个名字叫key_github的ssh key pair,目录在~/.ssh/,文件名可以按自己喜好修改,邮箱用自己的

复制代码
ssh-keygen -t rsa -b 4096 -C "xxxx@email.com" -f ~/.ssh/key_github

生成完记得激活加入ssh agent:

复制代码
eval "$(ssh-agent -s)"
你会看见提示:
Agent pid 12345

将生成的ssh 加入agent:

复制代码
ssh-add ~/.ssh/key_github

这时候~/.ssh 目录下应该会有两个文件,key_github 和 key_github.pub,用textEditor打开pub文件,复制里面的内容,

登陆github,右上角头像,点击settings,在左侧选择SSH and GPG keys,右边 add new ssh keys,粘贴刚才复制的内容,save

这样github获取了共钥,而本地macbook保留着私钥,就可以ssh连接了

打开terminal测试连接

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

提示
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
相关推荐
程序员柒叔32 分钟前
Diagram Design 解构:45 种图型如何用语义路由与 SVG 质量门交付
人工智能·github·agent·skills
逛逛GitHub33 分钟前
9 个神级 GitHub 项目助你蹭上抖音、小红书 Vibe 知识大赏热点。
github
m4Rk_42 分钟前
【论文阅读】Agent 记忆机制(119):EvoLife——让具身 Agent 把主动问到的答案沉淀为可复用的空间经验
论文阅读·人工智能·学习·开源·github
debugdynamo2 小时前
Netcatty:把 SSH 客户端做回工作台
运维·其他·ssh
时空无限2 小时前
ssh 直接免密输入 sudo 密码
运维·ssh
后台模板学习4 小时前
GitHub Actions 与 Jenkins 在日志监
运维·github·jenkins
miofly4 小时前
GitHub 今日推荐|auto-ontology:给 Agent 装上企业数据的语义索引
python·开源·github
miofly6 小时前
GitHub 日榜趋势速报 | 2026-11-04
开源·github
钱栈up15 小时前
GitHub 热榜上手|Orca:让多个编码 Agent 并排跑
github
wflynn19 小时前
GitHub 日榜趋势速报 | 2026-11-02
开源·github