如果你在使用apt-get升级Nginx时出现了类似下面的错误提示:

W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://nginx.org jessie Release: The following signatures were invalid: KEYEXPIRED 1471427554

W: Failed to fetch http://nginx.org/packages/mainline/debian/dists/jessie/Release

W: Some index files failed to download. They have been ignored, or old ones used instead.

apt-get的错误提示

可以看这里的解决方案。可惜那个网站的排版很糟糕,正确的代码是下面样子的(命令后面的注释是输出):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 运行代码之前这条命令的输出是下面的样子
apt-key list | grep "expired:"
# pub 2048R/7BD9BF62 2011-08-19 [expired: 2016-08-17]

# 之后可以用下两条命令修复这个问题
apt-key adv --recv-keys --keyserver keys.gnupg.net "C300EE8C"
# Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.6M95K7B10F --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-security-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg --recv-keys --keyserver keys.gnupg.net C300EE8C
# gpg: requesting key C300EE8C from hkp server keys.gnupg.net
# gpg: key C300EE8C: public key "Launchpad Stable" imported
# gpg: Total number processed: 1
# gpg: imported: 1 (RSA: 1)

apt-key adv --recv-keys --keyserver keys.gnupg.net "7BD9BF62"
# Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.tBKyYpYILK --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-security-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg --recv-keys --keyserver keys.gnupg.net 7BD9BF62
# gpg: requesting key 7BD9BF62 from hkp server keys.gnupg.net
# gpg: key 7BD9BF62: "nginx signing key <[email protected]>" 7 new signatures
# gpg: Total number processed: 1
# gpg: new signatures: 7

之后就都正常了。