zhengrenzhe's blog   About

Github 加V认证

系统环境 macOS Mojave 10.14.1

macOS默认未安装gpg,首先安装gpg

brew install gpg

生成gpg key

gpg --gen-key

查看生成的key

gpg --list-keys

-------------------------------------
pub   rsa2048 2018-11-11 [SC] [expires: 2020-11-10]
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
uid           [ultimate] zhengrenzhe <zhengrenzhe.niujie@gmail.com>
sub   rsa2048 2018-11-11 [E] [expires: 2020-11-10]

这里的AAAAAAA…就是key,接下来导出密钥

gpg --armor --export pub AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

-----BEGIN PGP PUBLIC KEY BLOCK-----
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-----END PGP PUBLIC KEY BLOCK-----

把导出的key粘贴到GitHub中 https://github.com/settings/gpg/new

接下来在项目中对commit启用签名,如果需要对所有项目全局生效,在config后增加--global参数即可

git config commit.gpgsign true
git config user.signingkey AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
git config alias.commit commit -S

commit时如果出现下面的错误:

error: gpg failed to sign the data
fatal: failed to write commit object

说明gpg签名工具链有问题,安装GPGTools即可解决。

← 优先队列