gnupg导入私钥的问题

21 views
Skip to first unread message

chenlhlinux

unread,
Dec 27, 2018, 11:20:45 AM12/27/18
to debian-chinese-gb@lists debian. org
大家好:
     刚刚我想在gpg中导入我的私钥,命令是:gpg --import 私钥文件名
报错信息为:
gpg: key 171F1787E07E87D2: "chenlhlinux (clh) <chenl...@qq.com>" not changed
gpg: error getting the KEK: End of file
gpg: Total number processed: 1
gpg:              unchanged: 1
gpg:       secret keys read: 1
经确认,私钥文件没有问题,且公钥可以正常导入。
请问这是什么原因,如何解决?


感谢!

Shell Xu

unread,
Dec 27, 2018, 8:58:56 PM12/27/18
to chenlhlinux, debian-chinese-gb@lists debian. org
我问个题外话。备份出来的时候有试过测试恢复/导入么?理论上私钥都是要测试恢复的,否则等发生问题发现备份出了错就有意思了。
简单测试方法是设定GNUPGHOME环境变量,这样会产生一个和当前隔离的环境。如果这个环境下可以正常导入,那说明基本无大问题了。
我一般还会把~/.gnupg连根拷贝一份,以防万一。

如果备份的时候已经经过了测试恢复,那么你可以试试找第二台机器去导入,确定是机器问题还是文件问题。
--
彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/

Tong Hui

unread,
Dec 27, 2018, 9:06:25 PM12/27/18
to chenlhlinux, debian-chinese-gb@lists debian. org
我觉得是你导出私钥的时候没有保存好吧。你是怎么导出私钥的?

一般来说 gpg --export-secret-keys 导出私钥会把导出的私钥直接输出到标准输出,这时候都会用 > 重定向到文件里,比如:

gpg --export-secret-keys --armour YOURKEY > SECRETKEYFILE

一般这样操作是不会有啥问题的,建议你重新导出一次。同时建议配合 --armour 或 --armor
选项使用,导出以后打开文件看看是不是完整。文件的开头结尾应该有-----BEGIN PGP SECRET KEY BLOCK----- 和
-----END PGP SECRET KEY BLOCK----- 标记的

On Fri, Dec 28, 2018 at 12:20 AM chenlhlinux <chenl...@qq.com> wrote:
>
--
/***
* @ 启智开源 编码自由
* @ Open Mind, Open Source, Coding for Freedom!
* @ 佟辉 Tong Hui (Tony)
* @ Email tonghuix AT member DOT fsf DOT org
* @ Web https://tonghuix.io
* @ XMPP/Jabber tonghuix AT member DOT fsf DOT org
*/

chenlhlinux

unread,
Dec 28, 2018, 12:48:29 AM12/28/18
to Tong Hui, debian-chinese-gb@lists debian. org
私钥在其他的机器上导入是正常的,私钥应该没有问题。

---Original---
From: "Tong Hui"<tong...@gmail.com>
Date: Fri, Dec 28, 2018 10:06 AM
To: "chenlhlinux"<chenl...@qq.com>;
Cc: "debian-chinese-gb@lists debian. org"<debian-c...@lists.debian.org>;
Subject: Re: gnupg导入私钥的问题

Shell Xu

unread,
Dec 28, 2018, 7:54:19 AM12/28/18
to chenlhlinux, debian-chinese-gb@lists debian. org
那么首先恭喜你,避免了最糟的情况。
能对比一下你正常机器和异常机器的差异么?两者分别是什么发行,gpg的版本号各是多少?

On Fri, Dec 28, 2018 at 1:40 PM chenlhlinux <chenl...@qq.com> wrote:
私钥在其他的机器上导入是正常的,私钥应该没有问题。
---Original---
From: "Shell Xu"<shell...@gmail.com>
Date: Fri, Dec 28, 2018 09:59 AM
To: "chenlhlinux"<chenl...@qq.com>;
Cc: "debian-chinese-gb@lists debian. org"<debian-c...@lists.debian.org>;
Subject: Re: gnupg导入私钥的问题
我问个题外话。备份出来的时候有试过测试恢复/导入么?理论上私钥都是要测试恢复的,否则等发生问题发现备份出了错就有意思了。
简单测试方法是设定GNUPGHOME环境变量,这样会产生一个和当前隔离的环境。如果这个环境下可以正常导入,那说明基本无大问题了。
我一般还会把~/.gnupg连根拷贝一份,以防万一。

如果备份的时候已经经过了测试恢复,那么你可以试试找第二台机器去导入,确定是机器问题还是文件问题。

On Fri, Dec 28, 2018 at 12:20 AM chenlhlinux <chenl...@qq.com> wrote:
大家好:
     刚刚我想在gpg中导入我的私钥,命令是:gpg --import 私钥文件名
报错信息为:
gpg: key 171F1787E07E87D2: "chenlhlinux (clh) <chenl...@qq.com>" not changed
gpg: error getting the KEK: End of file
gpg: Total number processed: 1
gpg:              unchanged: 1
gpg:       secret keys read: 1
经确认,私钥文件没有问题,且公钥可以正常导入。
请问这是什么原因,如何解决?


感谢!


--
彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/

chenlhlinux

unread,
Dec 28, 2018, 8:52:08 AM12/28/18
to Shell Xu, debian-chinese-gb@lists debian. org
我发现出问题的的机器上的gpg的版本号为2.2.12,正常的机器上的gpg的版本号为1.*。刚刚我在异常的机器上安装了1.4.23版本的gpg,现在已经可以正常导入。
感谢!
---Original---
From: "Shell Xu"<shell...@gmail.com>
Date: Fri, Dec 28, 2018 20:54 PM

Tong Hui

unread,
Dec 28, 2018, 9:14:51 AM12/28/18
to chenlhlinux, Shell Xu, debian-chinese-gb@lists debian. org
这就很奇怪了,理论上来说 gpg v1 导出的私钥 gpg v2 是应该能够支持的啊。

不如再生成一个测试密钥多做一些测试吧,也许是 gpg 的一个bug呢。

chenlhlinux

unread,
Dec 28, 2018, 10:51:30 AM12/28/18
to Tong Hui, Shell Xu, debian-chinese-gb@lists debian. org
刚刚我搭建了一个全新的环境并且安装了gpg 2.1.18,我在1.4.23中重新生成了一个密钥,经测试,公钥可以正常导入,导入私钥时的报错信息为:
root@localhost:~# gpg --import test.gpg
gpg: key 7F694E59020861E1: public key "testtest <test@test>" imported
gpg: error getting the KEK: End of file
gpg: Total number processed: 1
gpg:               imported: 1
gpg:       secret keys read: 1
我在2.1.18中生成密钥时也出现了错误,错误信息及其前后几行为:
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: agent_genkey failed: End of file
Key generation failed: End of file
root@localhost:~#
这很奇怪,可能是我的环境有问题。
---Original---
From: "Tong Hui"<tong...@gmail.com>
Date: Fri, Dec 28, 2018 22:14 PM
To: "chenlhlinux"<chenl...@qq.com>;
Cc: "Shell Xu"<shell...@gmail.com>;"debian-chinese-gb@lists debian. org"<debian-c...@lists.debian.org>;
Subject: Re: gnupg导入私钥的问题

Shell Xu

unread,
Dec 29, 2018, 12:11:45 AM12/29/18
to chenlhlinux, Tong Hui, debian-chinese-gb@lists debian. org
我查到有个bug是关于gpg-agent和gpg搭配导致此类报错的。这听起来也挺合理,因为里面有agent_genkey的报错。
能否请帮忙确认一下gpg-agent是否存在,如果存在请关闭测试一下。
Reply all
Reply to author
Forward
0 new messages