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

【git】重新生成并添加 SSH Key(Mac)
1. 检查本机已有 SSH key执行ls-al~/.ssh看看有没有id_rsa id_rsa.pub或者id_ed25519 id_ed25519.pub推荐使用ed25519。2. 生成新的 SSH Key执行ssh-keygen-ted25519-C你的GitLab邮箱例如ssh-keygen-ted25519-Cgegewuxxx.com一路回车Enter file in which to save the key:默认/Users/gegewu/.ssh/id_ed25519即可。如果提示Overwrite (y/n)?说明已有 key不想覆盖 → 输入n想更新 → 输入y3. 启动 ssh-agent执行eval$(ssh-agent-s)输出类似Agent pid 123454. 添加 SSH key执行ssh-add ~/.ssh/id_ed25519成功Identity added: /Users/gegewu/.ssh/id_ed255195. 复制公钥Macpbcopy~/.ssh/id_ed25519.pub现在 SSH key 已复制到剪贴板。6. 添加到 GitLab进入你的 GitLabUser Settings ↓ SSH Keys ↓ Add an SSH key填写Title例如MacBook-Air或者gegewu-macKey粘贴刚复制的内容类似ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIxxxxxx gegewuxxx.com点击Add key7. 测试 SSH你的地址ind-gitlab.dreame.tech测试ssh-Tgitind-gitlab.dreame.tech成功会类似Welcome to GitLab, gegewu!