OpenPGP常用命令手册
概述
详细手册参考man page或者gnupg wiki等在线资源。
生成密钥对
gpg --full-gen-key
列出当前密钥对
gpg --list-keys (公钥)gpg --list-secret-keys (私钥)
导出公钥
gpg --output <文件名> --armor --export <user-id>
导入公钥
gpg --import <文件名>
使用密钥服务器
gpg --send-keys <key-id>gpg --search-keys <user-id>gpg --recv-keys <key-id>
gpg --auto-key-locate <mechanisms> --locate-external-key <user-id> 从外部服务器获取用户公钥,user-id可以是邮箱地址。mechanisms默认是 local,wkd。
加密和解密
- 非对称加密:
gpg --recipient <user-id> -e <明文文件>(加密)gpg --output <明文文件> -d <加密文件>(解密) - 对称加密:
gpg -c <明文文件>(加密)gpg -o <明文文件> -d <加密文件>(解密)
密钥维护
- 备份私钥
gpg --export-secret-keys --armor <user-id> <文件名> - 导入私钥
gpg --import <私钥文件>
编辑密钥
gpg --edit-key <user-id>
签名
gpg --output <签名文件> --sign <原文件> gpg --output <签名文件> --clearsign <原文件> (不压缩)gpg --output <签名文件> --detach-sig <原文件> (只有签名)gpg --verify <签名文件> 验证签名