为什么GPG会生气,我该如何停止它?

我最近从一个Ubuntu安装迁移到另一个,并在此过程中更改了我的用户名。我将我的公钥/私钥对导入到gpg中,使用我的私钥进行解密工作得很好,但是每当我尝试使用我的公钥将某些内容加密给自己时,会收到以下警告信息:
It is NOT certain that the key belongs to the person named
in the user ID.  If you *really* know what you are doing,
you may answer the next question with yes.

之后它会问我是否真的想使用这个密钥(我总是回答“是”,因为实际上这是我的钥匙链中唯一的密钥,而且我知道它的来源)。我可以正常解密东西,那么为什么每次我尝试加密东西时,gpg都会发脾气呢?我该如何防止这个消息再次出现?

这个问题在stackoverflow上的旧回答有没有帮助?:http://stackoverflow.com/q/9460140/2422988 - Paul
@Paul,是的,那个链接帮了一点忙。我将我的密钥的“信任”级别设置为最高,似乎解决了问题。但问题到底是什么呢?为什么会发生这种情况?我是修复了它还是只是缓解了症状? - fouric
抱歉,InkBlend,恐怕我的筛选和比较搜索结果的能力超过了我对pgp的了解,在这种情况下,我不敢尝试将其作为答案。不过看起来Garrett知道发生了什么。 - Paul
3个回答

我遇到了同样的问题,但是我不再能够访问旧密钥。所以你可以用以下方法重新创建对旧密钥的信任:
gpg --edit-key YOUR@KEY.ID
gpg> trust
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

OP已经完成了这个(在评论中记录),但是把它陈述为答案也是好的。 - muru

我成功重现了你遇到的问题。我是这样做的:
$ gpg --no-default-keyring --keyring ./test-keyring  --secret-keyring ./test-secring --trustdb-name ./test-trustdb --no-random-seed-file --gen-key

<specified parameters and let it do its thing>

gpg: key 58018BFE marked as ultimately trusted
public and secret key created and signed.

<snip>

$

请注意,该过程将密钥标记为“最终信任”。
现在我要导出这些密钥:
$gpg --no-default-keyring --keyring ./test-keyring  --secret-keyring ./test-secring --trustdb-name ./test-trustdb --no-random-seed-file --export-secret-keys -a >private.key

$gpg --no-default-keyring --keyring ./test-keyring  --secret-keyring ./test-secring --trustdb-name ./test-trustdb --no-random-seed-file --export -a > public.key

现在我导入到一个新的gpg数据库中:
$gpg --no-default-keyring --keyring ./test2-keyring  --secret-keyring ./test2-secring --trustdb-name ./test2-trustdb --no-random-seed-file --import public.key

$gpg --no-default-keyring --keyring ./test2-keyring  --secret-keyring ./test2-secring --trustdb-name ./test2-trustdb --no-random-seed-file --import private.key

现在,如果我尝试使用新的密钥环进行加密,我会得到以下结果:
$ gpg --no-default-keyring --keyring ./test2-keyring  --secret-keyring ./test2-secring --trustdb-name ./test2-trustdb --no-random-seed-file -r Fake -e
gpg: AE3034E1: There is no assurance this key belongs to the named user

pub  1024R/AE3034E1 2013-06-13 Fake User <fake@example.com>
 Primary key fingerprint: AD4D BAFB 3960 6F9D 47C1  23BE B2E1 67A6 5801 8BFE
      Subkey fingerprint: 58F2 3669 B8BD 1DFC 8B12  096F 5D19 AB91 AE30 34E1

It is NOT certain that the key belongs to the person named
in the user ID.  If you *really* know what you are doing,
you may answer the next question with yes.

这是因为“信任网络”模型的原因。默认情况下,要使公钥受到信任,需要1个“终极”信任证书(通常是您亲自验证了相关人员的身份),或者3个“边缘”信任证书(其中有人您认识,而他们认识您认识的人...签署了该证书)。
由于gpg是一个安全应用程序,如果您尝试加密到一个未被列为受信任的密钥,它会向您发出警告。在这种情况下,您自己的密钥之所以不受信任,很简单。这是因为您没有从先前的gpg实例中导出信任关系。要做到这一点,请使用--export-ownertrust和--import-ownertrust命令。
如常,请参考man页面

1关键是所有与密钥可信度相关的数据都是与密钥环(包括秘钥和公钥)分开存储的!~/.gnupg/trustdb.gpg 存放了信任数据库,pubring.gpg 存放了公钥,secring.gpg 存放了私钥。请参阅 GnuPG 的文档获取更多信息。 - gertvdijk

你可以使用--always-trust标志来跳过这个提示信息。

2这绝对是真的,但那只是在缓解症状,而不是治本。你的解决方案就像因为得了癌症而吃阿司匹林一样... - Fabby
3--always-trust是一个不错的解决方案(在某些情况下),但如果问题中的密钥确实是用户自己的密钥,那么应该给予绝对的信任。 - Blacklight Shining
4我的问题是GPG的顽固坚持在我的程序文件加密中搞砸了我的密钥环,而且在我安装软件的每个虚拟机上都以不同的方式出现问题。 - bbozo
@BlacklightShining 如果我还没有能够验证,Evolution不允许对该地址的邮件进行加密。不知道为什么将文本加密给某人需要绝对的信任 - 而只有边缘的信任是不可能的。 - Izzy