PGP 密钥常用命令记录

Published: Sat 13 January 2024

本文记录了在使用 gpg 管理 PGP 密钥时的一些常用命令.

查看本地公钥:

gpg -k --keyid-format long

验证私钥密码:

gpg --export-secret-keys -a your_uid > /dev/null && echo OK

发布你的公钥到 key server:

gpg --keyserver keys.openpgp.org --send-keys <key_id>

导出公钥/私钥:


Integrate with git

添加如下代码到 ~/.zshrc:

export GPG_TTY=$(tty)

设置 ~/.gitconfig:

[user]
    signingkey = XXXXXXXXXX
[commit]
    gpgsign = true

Integrate with ssh

在远程主机使用本地的 PGP 密钥: https://wiki.gnupg.org/AgentForwarding

参考

  • https://ulyc.github.io/2021/01/13/2021%E5%B9%B4-%E7%94%A8%E6%9B%B4%E7%8E%B0%E4%BB%A3%E7%9A%84%E6%96%B9%E6%B3%95%E4%BD%BF%E7%94%A8PGP-%E4%B8%8A/
  • https://ulyc.github.io/2021/01/26/2021%E5%B9%B4-%E7%94%A8%E6%9B%B4%E7%8E%B0%E4%BB%A3%E7%9A%84%E6%96%B9%E6%B3%95%E4%BD%BF%E7%94%A8PGP-%E4%B8%8B/
  • https://blog.ginshio.org/2020/gpg_started_guide/

links