【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!
相关推荐
king135987455015 小时前
LFM2.5-24B-A2B Mac 本地部署:内存估算、GGUF/MLX 与 Python 预检脚本
人工智能·macos
骑着蜗牛撵大象32716 小时前
链路层不只是 MAC:以太网帧、ARP 与 802.1Q VLAN 的逐跳拆解
计算机网络·macos·ar·vlan·mac地址·链路层
程序员差不多先生17 小时前
Anthropic 用 5 个月重写了 Git:当 AI Agent 把版本控制系统逼到墙角
人工智能·git·elasticsearch·deepseek v4 pro·kimi k3·glm 5.3·qwen3.7 max
程序员-Benothing17 小时前
SSH从入门到精通:密钥登录、config配置、跳板机
linux·运维·服务器·ssh
一条泥憨鱼17 小时前
【计算机网络】| 从 MAC 到 NAT 的跨网段通信全链路
服务器·网络·学习·计算机网络·macos
leo_厉锵18 小时前
GIT习题
git
catoop1 天前
用 Shell 包装函数,让单个命令拥有专属配置
git
Zguigo1 天前
学会更高效的理解AI的输出?
人工智能·git·ai
鬼手点金2 天前
上下文:Agent 的眼睛
java·前端·人工智能·git·深度学习
IT大白鼠2 天前
AI SSH 运维助手 V13.0内部版七项私有新特性全解
运维·人工智能·ssh