分两步:
- 生成PGP的key
- 使用pgp pubkey给tag签名
生成PGP key
GPG = GnuPG,是Gnu提供的一个产生PGP秘钥的工具。
生成秘钥:
$ gpg --gen-key
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
gpg: directory '/home/steveliu/.gnupg' created
gpg: keybox '/home/steveliu/.gnupg/pubring.kbx' created
Note: Use "gpg --full-generate-key" for a full featured key generation dialog.
GnuPG needs to construct a user ID to identify your key.
Real name: zhangsan
Email address: zhangsan@163.com
You selected this USER-ID:
"zhangsan <zhangsan@163.com>"
输入你的Real name(这个后面作为key的userid使用)和Email address。
输入密码来保护这把密钥(后续在使用密钥的时候,需要输入密码)
查看秘钥:
gpg --list-secret-keys --keyid-format LONG
导出公钥:
导出公钥:
gpg --armor --output public-key-gmail.txt --export USERID
导出私钥:
gpg --armor --output secret-key-gmail.txt --export-secret-keys USERID
使用pgp pubkey给tag签名
git tag v1.0 -u MASTERKEYID
可能遇到的问题及解决
打tag失败
error: gpg failed to sign the data
error: unable to sign the tag
可以试试增加环境变量
export GPG_TTY=$(tty)