关于 glab-ssh-key
用于管理 GitLab 账户 SSH 密钥的 glab skill,支持密钥生命周期操作、按指纹替换和 JSON 自动化输出,并强调仅上传公钥。
主要功能
- 01添加、列出、获取和删除密钥
- 02按指纹替换匹配密钥
- 03设置密钥标题、用途和有效期
- 04列表和获取命令支持 JSON 输出
- 05提供避免上传私钥的指引
适用场景
- 01为 Git 操作登记公钥
- 02检查账户关联的密钥
- 03替换已登记的密钥
- 04在 Agent 自动化中使用密钥数据
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ vince-winkintel/ gitlab-cli-skills --skill glab-ssh-key安装后在 Claude Code 中输入/glab-ssh-key确认已加载。
附带文件references/commands.md
详细介绍
glab ssh-key
概览
来自经过验证的发布二进制文件的完整帮助信息;不可变捕获 ID
5686d7484对应VERSION中的发布版本和归档校验和。仅移除了行尾空白;保留缩进、空行、换行、截断内容和产品拼写。
Add, list, get, and delete the SSH keys associated with your account.
GitLab uses SSH keys to authenticate Git operations over SSH, and,
depending on each key's usage type, to verify signed commits.
USAGE
glab ssh-key <command> [command] [--flags]
COMMANDS
add [key-file] [--flags] Add an SSH key to your GitLab account.
delete [<key-id>] [--flags] Deletes a single SSH key specified by the ID.
get [<key-id>] [--flags] Returns a single SSH key specified by the ID.
list [--flags] Get a list of SSH keys for the currently authenticated user.
FLAGS
-h --help Show help for this command.
-R --repo Select another repository. You can use either OWNER/REPO or GROUP/NAMESPACE/REPO. The full URL or Git URL is also accepted.
⚠️ 安全警告:仅限公钥
务必确认上传的是公钥,而不是私钥。
- ✅ 公钥:
~/.ssh/id_rsa.pub、~/.ssh/id_ed25519.pub(带.pub扩展名) - ❌ 私钥:
~/.ssh/id_rsa、~/.ssh/id_ed25519(不带扩展名——切勿上传)
将私钥上传到 GitLab 会暴露你的凭据。运行 glab ssh-key add 前,请仔细检查文件名。
# ✅ Safe — public key
glab ssh-key add ~/.ssh/id_ed25519.pub --title "My Laptop"
# ❌ NEVER do this — private key
# glab ssh-key add ~/.ssh/id_ed25519 --title "My Laptop"
上传前,请确认你的密钥是公钥:
# Should start with 'ssh-rsa', 'ssh-ed25519', 'ecdsa-sha2-*', etc.
head -c 20 ~/.ssh/id_ed25519.pub
快速开始
glab ssh-key --help
替换现有密钥
即使已注册的密钥已过期,GitLab 仍会拒绝重复的公钥指纹。确认已通过身份验证的账户以及要替换的密钥后,使用:
glab ssh-key add ~/.ssh/id_ed25519.pub --title "My Laptop" --expires-at 2027-01-01 --replace
--expires-at 接受仅包含日期的值(例如 2027-01-01,表示 UTC 午夜)和完整的 RFC 3339 时间戳(例如 2027-01-01T00:00:00Z)。标志帮助信息展示的是完整时间戳格式;CLI 解析器也接受上面的仅日期示例。
--replace 会解析公钥,分页搜索当前用户的密钥,查找 SHA256 指纹相同的密钥,删除匹配项,然后使用指定的标题、用途类型和过期时间添加所提供的密钥。如果没有匹配项,则会正常添加密钥。此操作不会要求确认替换,也不会回滚:如果删除后添加失败,旧密钥将无法恢复。使用此标志前,请检查匹配的密钥,并确保还有其他可用的授权访问方式。这会重新注册同一个公钥,不会生成或轮换密钥材料。
结构化输出
glab ssh-key list 和 glab ssh-key get 支持通过 --output json / -F json 输出结构化数据,便于 Agent 自动化处理。
# List SSH keys with JSON output
glab ssh-key list --output json
glab ssh-key list -F json
# Get a specific SSH key with JSON output
glab ssh-key get <key-id> --output json
glab ssh-key get <key-id> -F json
子命令
完整的 --help 输出请参阅 references/commands.md。