0%

apt update 报 Release 过期或证书错误时先查时钟

apt update 的这两类报错经常被当成源坏了。Release 文件「还没生效」或「已经过期」,以及 HTTPS 证书不被信任,都先看机器时间。时钟快了或慢了,签名文件的有效期和证书的有效期都会对不上。

先把完整报错留住:

1
2
3
sudo apt update
date -u
timedatectl status

System clock synchronized: yes 且 UTC 时间和你知道的现在差不多,再往下看源。差了几小时以上,先把时间校回来:

1
sudo timedatectl set-ntp true

没有 NTP 可用时,用你确认过的时间设一次。设完再跑 apt update。时间不对时去改 sources.list 解决不了。

Release 文件无效

类似这样:

1
2
E: Release file for https://deb.debian.org/debian/dists/trixie/Release is not valid yet (invalid for another 3h 10min).
E: Release file for https://deb.debian.org/debian/dists/trixie/Release is expired (invalid since 14h 2min).

not valid yet 是本机时钟慢了,或者这份 Release 的起始时间在未来。expired 是本机时钟快了,或者镜像长期没同步。

时钟已经正确、报错仍是 expired,再查是不是镜像停更。换官方源试一次:

1
curl -fsI https://deb.debian.org/debian/dists/trixie/Release | head

能拿到 HTTP/2 200 或 HTTP/1.1 200,说明地址通。仍说 expired,看这份文件的 Date 和 Valid-Until,和 date -u 比。

Acquire::Check-Valid-Until "false" 可以跳过有效期检查。那是镜像确实旧、又必须先装上包时的临时办法,时钟错了不要用它盖住。

证书错误

报错里出现 Certificate verification failed 或 certificate has expired,同样先看 date -u。时间落在证书有效期外面,校时之后证书错误会一起消失。

时间正确仍失败,看证书日期:

1
echo | openssl s_client -connect deb.debian.org:443 -servername deb.debian.org 2>/dev/null | openssl x509 -noout -dates

notAfter 已过,是对方证书或中间证书的问题,不是把 https 改成 http 就能当常规做法。本机信任库太旧时,在时间正确的前提下重装:

1
sudo apt install --reinstall ca-certificates

apt 已经完全跑不起来、连这个包都装不上时,用另一台时间正确的机器把 ca-certificates 的 deb 下载下来再 dpkg -i。源地址本身写错时,报错通常是找不到 Release 或 404,而不是有效期。升到 Debian 13 之后的源格式见 sources.list 换成 deb822。