git使用过程中若使用过GPG KEY为commit进行签名,在一段时间未使用后,再次对某个库进行操作,提交时会发现,提示gpg签名失败。
error: gpg failed to sign the data
fatal: failed to write commit object
通过命令查看具体账户下的gpg keys.
$ gpg2 --list-secret-keys --keyid-format long
/home/nn/.gnupg/pubring.kbx
---------------------------------
sec rsa4096/3CF8D791AB81AE55 2020-08-26 [SC]
A598B8F2448C8B19C2ECF7803CF8D791AB81AE55
uid [ultimate] Nicholas <[email protected]>
ssb rsa4096/A0B38A3FA93702EB 2020-08-26 [E]
sec rsa4096/5BA245F4CC9794AF 2020-10-28 [SC] [expired: 2020-10-29]
D377D1F46DDCFF450B24FCD05BA245F4CC9794AF
uid [ expired] sanren1024 (github gpg) <[email protected]>
可以看到ID为5BA245F4CC9794AF
的状态是expired,即过期了。
使用命令对gpg key进行编辑,进入到编辑命令行模式。
$ gpg --edit-key 5BA245F4CC9794AF
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.
Secret key is available.
sec rsa4096/5BA245F4CC9794AF
created: 2020-10-28 expired: 2020-10-29 usage: SC
trust: ultimate validity: expired
ssb rsa4096/940927C936A8FDEA
created: 2020-10-28 expired: 2020-10-29 usage: E
[ expired] (1). sanren1024 (github gpg) <[email protected]>
gpg>
提示符gpg>
表示进入到了编辑命令行模式,接着输入expire
以更新取消日期.
gpg> expire
Changing expiration time for the primary key.
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)
查看到提示,可以输入的格式标题下次取消的时间点。接着按格式进行输入,这里选择输入180
即180天后再次取消。
Key is valid for? (0) 180
Key expires at Tue 29 Jun 2021 10:42:58 AM CST
Is this correct? (y/N) y
sec rsa4096/5BA245F4CC9794AF
created: 2020-10-28 expires: 2021-06-29 usage: SC
trust: ultimate validity: ultimate
ssb rsa4096/940927C936A8FDEA
created: 2020-10-28 expired: 2020-10-29 usage: E
[ultimate] (1). sanren1024 (github gpg) <[email protected]>
gpg: WARNING: Your encryption subkey expires soon.
gpg: You may want to change its expiration date too.
gpg>
这样再次看到的状态是ultimate
,不再是expired
。
因为重新更新了取消时间,需要输入trust
命令。
gpg> trust
sec rsa4096/5BA245F4CC9794AF
created: 2020-10-28 expires: 2021-06-29 usage: SC
trust: ultimate validity: ultimate
ssb rsa4096/940927C936A8FDEA
created: 2020-10-28 expired: 2020-10-29 usage: E
[ultimate] (1). sanren1024 (github gpg) <[email protected]>
Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)
1 = I don't know or won't say
2 = I do NOT trust
3 = I trust marginally
4 = I trust fully
5 = I trust ultimately
m = back to the main menu
Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y
sec rsa4096/5BA245F4CC9794AF
created: 2020-10-28 expires: 2021-06-29 usage: SC
trust: ultimate validity: ultimate
ssb rsa4096/940927C936A8FDEA
created: 2020-10-28 expired: 2020-10-29 usage: E
[ultimate] (1). sanren1024 (github gpg) <[email protected]>
提示输入信任key的成都,根据需要进行选择即可,最后输入save
命令,保存后退出。
gpg> save
上述步骤完成后,gpg key就被更新了,接着需要在确保设置了gpg签名后,进行重新提交。
$ git config --local commit.gpgSign true # 使用gpg签名
$ git config --local user.signingKey 5BA245F4CC9794AF # 设置gpg签名的KEY_ID
可以使用上述命令,重新设置库的gpg。
接着就可以进行正常commit操作。