关于 ssh-key-management
用于管理 Acquia Cloud SSH 密钥的技能,涵盖创建、上传、查看、列出和删除密钥,适合配置 IDE、服务器、代码仓库或 CI/CD 的访问。
主要功能
- 01创建并上传 SSH 密钥
- 02列出密钥及指纹
- 03查看或删除已注册密钥
- 04配置 IDE 的 SSH 访问
- 05为 CI/CD 准备密钥
适用场景
- 01配置 Acquia IDE 的 SSH 访问
- 02注册已有公钥
- 03删除账户中的旧密钥
- 04为 CI/CD 准备 SSH 认证
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ acquia/ acquia-skills --skill ssh-key-management安装后在 Claude Code 中输入/ssh-key-management确认已加载。
详细介绍
管理 SSH 密钥
适用于:
- 为 Acquia Cloud 添加或生成 SSH 密钥
- 列出或删除 SSH 密钥
- 为 IDE 或 CI/CD 流水线设置 SSH 访问
SSH 密钥可用于安全地验证 Acquia Cloud 资源的身份,无需输入密码。
为什么使用 SSH 密钥?
SSH 密钥可用于:
- 安全地访问 IDE,无需输入密码
- 向仓库推送代码
- 在服务器上执行远程命令
- 在脚本或 CI/CD 流水线中自动部署
列出 SSH 密钥
查看所有 SSH 密钥
acli ssh-key:list
输出:
SSH Keys for your account:
[0] My Laptop (generated 2024-01-15)
Fingerprint: ab:cd:ef:12:34:56:78:90
[1] Work Desktop (generated 2024-02-01)
Fingerprint: 11:22:33:44:55:66:77:88
列出各 IDE 的密钥
acli ide:ssh-key:list
生成新的 SSH 密钥
交互式创建 SSH 密钥
acli ssh-key:create
此操作将:
- 提示输入标签(例如,“我的笔记本电脑”“CI 服务器”)
- 生成公钥/私钥对
- 将公钥存储到你的 Acquia 账户中
- 在本地保存私钥(通常为
~/.ssh/id_rsa)
示例:
$ acli ssh-key:create
? Enter a label for this SSH key: My Laptop
✓ SSH key created!
Public key added to your account.
Private key saved to: ~/.ssh/id_rsa
Fingerprint: ab:cd:ef:12:34:56:78:90
注意: 标签提示是生成密钥并将其永久添加到你的 Acquia 账户之前的最后一步。按 Enter 前,请确认标签正确无误。
上传现有 SSH 密钥
如果你已有 SSH 密钥,可以上传,无需重新生成:
acli ssh-key:upload --filepath ~/.ssh/id_rsa.pub --label "Existing Key"
也可以使用交互方式:
acli ssh-key:upload
系统会提示你选择密钥文件并输入标签。
跳过等待传播
默认情况下,acli 会等待密钥传播到所有服务器。使用以下命令可跳过等待:
acli ssh-key:upload --filepath ~/.ssh/id_rsa.pub --label "My Key" --no-wait
一步完成创建和上传
在本地生成新密钥,并通过一条命令将其上传到 Cloud Platform:
acli ssh-key:create-upload
选项:
acli ssh-key:create-upload \
--filename=my_key \
--password="" \
--label="My New Key" \
--no-wait
检查 SSH 密钥
通过指纹获取特定密钥的详细信息:
acli ssh-key:info --fingerprint="ab:cd:ef:12:34:56:78:90"
这有助于在删除前确认已注册的是哪个密钥。
删除 SSH 密钥
从账户中移除密钥
acli ssh-key:delete
系统会提示你选择要删除的密钥:
? Select the SSH key to delete: [0] My Laptop
? Delete "My Laptop"? (yes/no)
✓ SSH key deleted.
非交互式删除
acli ssh-key:delete --public-key "ab:cd:ef:12:34:56:78:90"
在 IDE 中使用 SSH 密钥
SSH 连接到 IDE
设置好 SSH 密钥后,即可连接到 IDE:
# Note: Use the IDE ides-hostname, not the web URL
ssh -i ~/.ssh/id_rsa [email protected]
在 IDE 中设置通过 SSH 使用 git
请使用 SSH,而不是需要密码验证的 HTTPS:
# Configure your IDE's Git to use SSH
git remote set-url origin [email protected]:yourorg/yourrepo.git
# Now push without entering a password
git push origin main
导出公钥以供其他系统使用
# Show your public key
cat ~/.ssh/id_rsa.pub
# Copy it to GitLab, GitHub, internal systems, etc.
最佳实践
1. 每台设备使用一个密钥
为每台机器创建单独的密钥:
# Personal laptop
acli ssh-key:create --label "Personal MacBook"
# Work desktop
acli ssh-key:create --label "Work Desktop"
# CI/CD server
acli ssh-key:create --label "Jenkins CI Server"
2. 使用描述性标签
# ✓ Good
acli ssh-key:create --label "2024 MacBook Pro - Home"
acli ssh-key:create --label "GitHub Actions CI"
# ✗ Bad
acli ssh-key:create --label "Key 1"
3. 撤销旧密钥
移除不再使用的密钥:
acli ssh-key:delete
4. 保护私钥
# Permissions should be 600 (read/write for owner only)
chmod 600 ~/.ssh/id_rsa
5. 使用 SSH Agent
macOS:
# Add to ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
Linux:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
高级用法:用于 CI/CD 的 SSH
为 CI/CD 流水线生成密钥
acli ssh-key:create --label "GitHub Actions CI"
然后:
- 复制私钥
- 将其添加到 CI/CD 提供商的机密信息中(GitHub Secrets、GitLab CI/CD Variables 等)
- 在 CI 脚本中使用
GitHub Actions 示例:
- name: Deploy to Acquia
uses: actions/checkout@v2
env:
SSH_KEY: ${{ secrets.ACQUIA_SSH_KEY }}
run: |
mkdir -p ~/.ssh
echo "$SSH_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
acli api:environments:code-switch <env-id> main
MEO(V3)订阅: 请使用
acli api:v3:environments:create-deployment <environmentId> true refs/heads/main, 而不是api:environments:code-switch(参见 MEO 部署)。
相关主题
评论
支持 Markdown