GitHub中GPG认证使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WMSOK/article/details/79058430

1. 打开本地的git bash命令窗口,执行gpg –gen-key:

gpg --gen-key
Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 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) 10y
Key expires at 2028011210:01:14 GMT
Is this correct? (y/N) y

接下来就是配置姓名、邮箱、注释和密码,这些信息也不需要和GitHub账号信息有任何关联。填一些有意义的就好。

最后会输出信息中最后三行,如下,其中pub为公钥,C51F99A5 为公钥Key;sub为私钥768FFEAA为私钥Key,过期时间为2028年

pub   2048R/C51F99A5 2018-01-14 [expires: 2028-01-12]
      Key fingerprint = XXXX 3596 8DA0 616E 8E39 ABCD 5823 8C2F EFGN YYYY
uid                  realname (github) <xxxx@163.com>
sub   2048R/768FFEAA 2018-01-14 [expires: 2028-01-12]

2、获取GPG Keys

gpg --armor --export <GPG key ID>

GPG key ID为私钥ID或公钥ID都可以。输出的内容就是我们要的GPG Keys了。点开GitHub的GPG配置页面,粘贴该内容。

3、本地配置Git全局开启GPG认证,并配置GPG key ID

git config --global commit.gpgsign true
git config --global user.signingkey <GPG key ID>

4、我们可以通过以下命令查询本机所有的Key:

gpg --list-secret-keys
gpg --list-keys

然后可以通过 Key ID查出对应的Key

猜你喜欢

转载自blog.csdn.net/WMSOK/article/details/79058430
gpg
今日推荐