655 字
3 分钟
MacBook Air 2025(M4)SSH 密钥配置指南

MacBook Air 2025(M4)SSH 密钥配置指南#

目标:本机生成 Ed25519 密钥对 → 在云效(Codeup)添加 SSH 公钥 → 通过 SSH 正常 clone / pull / push


0️⃣ 前置检查#

Terminal window
ssh -V
git --version

1️⃣ 生成专用于云效 Codeup 的 Ed25519 密钥对#

💡 建议为每个平台单独生成一套密钥,避免与 GitHub / GitLab 等平台互相干扰。

Terminal window
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519_codeup

出现 passphrase 提示时直接按两次回车留空,后续使用无需输入任何密码:

Enter passphrase (empty for no passphrase): ← 直接回车
Enter same passphrase again: ← 直接回车

🔒 不设 passphrase 的安全性说明:macOS 本身有登录密码 + FileVault 磁盘加密保护,个人开发机已经够用。

生成结果:

文件路径
私钥~/.ssh/id_ed25519_codeup
公钥~/.ssh/id_ed25519_codeup.pub

2️⃣ 固定 Codeup 使用该私钥#

创建 / 编辑 ~/.ssh/config

Terminal window
touch ~/.ssh/config
chmod 600 ~/.ssh/config

写入(或追加)以下内容:

Host codeup.aliyun.com
HostName codeup.aliyun.com
User git
Port 22
IdentityFile ~/.ssh/id_ed25519_codeup

💡 本机有多把密钥时,这一步确保访问 Codeup 时始终使用正确的密钥,不会”随机挑一把”导致认证失败。


3️⃣ 拷贝公钥到剪贴板#

Terminal window
tr -d '\n' < ~/.ssh/id_ed25519_codeup.pub | pbcopy

也可直接打开 .pub 文件全选复制,要求从 ssh- 开头一直到邮箱注释结尾完整复制


4️⃣ 在云效(Codeup)添加 SSH 公钥#

  1. 登录 云效
  2. 页面右上角头像 → 个人设置
  3. 左侧选择 SSH 公钥
  4. 粘贴公钥内容,填写标题,设置作用范围(读写 / 只读)与过期时间
  5. 点击 添加 保存

5️⃣ 验证 SSH 认证#

Terminal window
ssh -v git@codeup.aliyun.com

✅ 成功时会看到认证通过(publickey)及 Welcome to Codeup, <用户名>! 提示。Codeup 不提供 shell 登录,提示后主动断开连接属于正常现象


6️⃣ 使用 SSH 地址 clone 仓库#

在 Codeup 仓库页面 → 克隆/下载 → 选择 SSH,地址格式如下:

格式示例
SSH 协议头ssh://git@codeup.aliyun.com:22/namespace/repo.git
scp 风格git@codeup.aliyun.com:namespace/repo.git
Terminal window
git clone git@codeup.aliyun.com:namespace/repo.git

7️⃣ 常见故障快速定位#

clone / push 时认证失败(本机有多把密钥)#

原因:SSH 可能”随机挑一把密钥”导致用错了 key。

解决:确保 ~/.ssh/config 已将 codeup.aliyun.com 绑定到 IdentityFile ~/.ssh/id_ed25519_codeup(见第 2 步)。

Permission denied (publickey)#

排查步骤

  1. 确认公钥已正确添加到云效(第 4 步)
  2. ssh -v git@codeup.aliyun.com 查看详细日志,确认加载的是 id_ed25519_codeup 这把密钥
  3. 确认 .pub 文件内容完整粘贴,没有多余换行或空格

📎 参考链接#

MacBook Air 2025(M4)SSH 密钥配置指南
https://twenhub.com/posts/macbook-air-2025-m4-ssh-mi-yao-pei-zhi-zhi-nan/
作者
Twenhub
发布于
2026-02-27
许可协议
CC BY-NC-SA 4.0