【git】重新生成并添加 SSH Key(Mac)

1. 检查本机已有 SSH key

执行:

bash 复制代码
ls -al ~/.ssh

看看有没有:

text 复制代码
id_rsa
id_rsa.pub

或者:

text 复制代码
id_ed25519
id_ed25519.pub

推荐使用 ed25519


2. 生成新的 SSH Key

执行:

bash 复制代码
ssh-keygen -t ed25519 -C "你的GitLab邮箱"

例如:

bash 复制代码
ssh-keygen -t ed25519 -C "gegewu@xxx.com"

一路回车:

text 复制代码
Enter file in which to save the key:

默认:

text 复制代码
/Users/gegewu/.ssh/id_ed25519

即可。

如果提示:

text 复制代码
Overwrite (y/n)?

说明已有 key:

  • 不想覆盖 → 输入 n
  • 想更新 → 输入 y

3. 启动 ssh-agent

执行:

bash 复制代码
eval "$(ssh-agent -s)"

输出类似:

text 复制代码
Agent pid 12345

4. 添加 SSH key

执行:

bash 复制代码
ssh-add ~/.ssh/id_ed25519

成功:

text 复制代码
Identity added: /Users/gegewu/.ssh/id_ed25519

5. 复制公钥

Mac:

bash 复制代码
pbcopy < ~/.ssh/id_ed25519.pub

现在 SSH key 已复制到剪贴板。


6. 添加到 GitLab

进入你的 GitLab:

复制代码
User Settings
    ↓
SSH Keys
    ↓
Add an SSH key

填写:

Title

例如:

复制代码
MacBook-Air

或者:

复制代码
gegewu-mac

Key

粘贴刚复制的内容:

类似:

复制代码
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIxxxxxx gegewu@xxx.com

点击:

复制代码
Add key

7. 测试 SSH

你的地址:

复制代码
ind-gitlab.dreame.tech

测试:

bash 复制代码
ssh -T git@ind-gitlab.dreame.tech

成功会类似:

text 复制代码
Welcome to GitLab, @gegewu!
相关推荐
qq_349447951 小时前
Linux系统,安装git,从使用git下载仓库(GitHub, Gitee, GitLab 等),并且使用ssh密钥,可以直接执行git pull
linux·git·ssh
mCell4 小时前
谁在为 AI 开车:Agent 浏览器生态调研(2026)
chrome·macos·agent
凯尔萨厮9 小时前
Git(学习笔记)
笔记·git·学习
一技安身11 小时前
【Git】零基础入门实战教程(Windows 完整版,适配竞赛仓库)
windows·git
LXY_BUAA14 小时前
Git_在飞牛中部署 GitLab_20260817
git·gitlab
阳墨余16 小时前
Git 同时管理 Gitee 和 GitHub 的 SSH 配置实战
git·gitee·github
fengyehongWorld1 天前
Git 认证凭据管理
git
sudebao点com1 天前
一次“Google 能打开,FlexTV 打不开”的 DNS 故障排查:从 curl 超时到完整证据链
windows·macos·https·cdn·dns·nslookup·网络排错
暮云星影1 天前
git版本发布
git·gitee·github·gitea
乌夷1 天前
Git Flow 分支模型
git