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.
相关推荐
u1301301 小时前
GitHub 热榜项目:日榜(2026-10-14)
人工智能·github
GeofferyLibrom2 小时前
# Mac 平台 Chiaki-ng 配置指南: Base64 ID 获取
macos·base64·chiaki-ng·npsso·psnawp
GeofferyLibrom2 小时前
PS5 自动化挂机指南:基于 Mac + Chiaki-ng 视觉识别——龙信2自动挂机实战
运维·macos·自动化
bing_feilong2 小时前
vscode: ssh Got bad result from install script
ide·vscode·ssh
月月如常2 小时前
Typora 粘贴图片时 PicGo 弹窗的解决方案
macos·typora·picgo
andyweike3 小时前
CGRect
macos·objective-c·cocoa
誰能久伴不乏3 小时前
QT工业上位机一次「指令静默丢失」的排查
qt·docker·github
胡大伟3 小时前
麦当劳的开发者大赛:麦当劳 MCP 实测——一个藏在 inputSchema 里的参数
github
疯狂敲代码的老刘3 小时前
DigUp:2.8千星开源Mac语义搜索,Google DeepMind模型本机运行找遍所有文件
macos
大苦根3 小时前
RAG 重排器对比:从 Bi-Encoder 到 Cross-Encoder,以及为什么 bge-reranker-v2-m3 是中文 RAG 的默认答案
github