GitHub中GPG认证使用

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值