生成 GPG 公钥
提示
GPG(GNU Privacy Guard)公钥是用于加密和验证数据的重要工具。它可以用于保护您的电子邮件通信、验证软件包的完整性以及签名文档。
在不同的操作系统中获取 GPG 公钥的方法略有不同。以下是针对 Windows、macOS 和 Linux 系统的详细步骤:
Windows系统获取GPG公钥
安装GPG
- 访问 官方Gpg4win网站 下载Gpg4win安装包。
- 运行下载的安装程序并按照提示完成安装。
生成和导出GPG公钥
打开 命令提示符 或 PowerShell ,然后使用以下命令:
生成新的GPG密钥对(如果您还没有):
gpg --full-generate-key
按照页面提示生成GPG 密钥:
Please select what kind of key you want:
(1) RSA and RSA
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
(9) ECC (sign and encrypt) *default*
(10) ECC (sign only)
(14) Existing key from card
Your selection? 1 //建议选择 RSA and RSA类型的密钥
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096 //为保障安全性,建议长度为 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) //根据需要配置 GPG 密钥有效期
Key does not expire at all
Is this correct? (y/N) y //再次确认配置
GnuPG needs to construct a user ID to identify your key.
Real name: gitcode //配置您的姓名
Email address: email@gitcode.com //配置您的邮箱,注意邮箱必须要与 GitCode 的默认邮箱一致
Comment:
You selected this USER-ID:
"gitcode <email@gitcode.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o //配置不变,之后会弹出密码输入框,输入密码后继续
列出GPG密钥,以找到您的公钥 ID:
gpg --list-keys
导出GPG公钥(替换 YOUR_KEY_ID 为您的公钥 ID):
gpg --armor --export YOUR_KEY_ID