概览:
起因
偶尔在GitHub看到有些某些贡献者提交代码时,在github网站显示commit信息时,会显示Verified
。发现是使用了gpg。
https://docs.github.com/en/github/authenticating-to-github/about-commit-signature-verification
安装gpg
首先是安装和查看gpg版本
1 | $ brew install gpg |
创建gpg key
https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key
- 查看已存在的keys
1 | gpg --list-secret-keys --keyid-format LONG |
如果需要生成新的keys
1 | gpg --full-generate-key |
- RSA and RSA
- 4096
- key does not expire
- 其他的信息自己看着填写
例如生成了以下keys
1 | pub rsa4096 2021-04-24 [SC] |
导出公钥
1 | # 可以写完整的pub id, |
将导出的公钥写入到github设置的gpg里面。
git使用gpg进行签名
https://docs.github.com/en/github/authenticating-to-github/telling-git-about-your-signing-key
1 | git config --global user.signingkey 97C0CDDADFC43DAC |
并将这个export GPG_TTY=$(tty)
添加到.bashrc或者.zshrc,不然commit时无法进行签名,需要输入生成keys时的密码。
然后签名提交,看看效果
开启全局签名
不开启全局签名,就需要每次在提交时加上
-S
参数。像git commit -S -m "this is cool code"
1 | git config --global commit.gpgsign true |