You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派Debian 11系统NTP时间同步失败及证书验证错误问题求助

解决树莓派Debian系统时间不同步导致证书验证失败的问题

我来帮你搞定这个问题!先看你的系统时间显示是2021年7月,这才是所有问题的根源:

  • 证书验证失败是因为系统时间远早于证书的生效时间,服务器返回的证书在当前系统时间下还没“生效”,所以被判定为不可信
  • NTP服务默认不会处理超过1000秒的时间偏移,所以即使你配置了NTP,也没法自动同步到正确时间

咱们一步步解决:

1. 手动临时修正系统时间

先把时间改成接近当前的正确时间,让后续的NTP同步和证书验证能正常工作:

# 手动设置时间,替换成当前实际的年月日时分秒
date -s "2024-05-20 14:30:00"
# 或者用timedatectl设置(更推荐)
timedatectl set-time "2024-05-20 14:30:00"

2. 强制同步NTP时间

手动改完时间后,用ntpdate强制同步到NTP服务器(先停止正在运行的ntpd服务,避免冲突):

# 停止ntpd服务
systemctl stop ntp
# 用阿里云NTP服务器强制同步
ntpdate ntp.aliyun.com
# 重启ntpd服务
systemctl start ntp

3. 验证同步状态

运行以下命令确认NTP是否正常同步:

# 查看NTP服务器连接状态,注意reach列的值(非0表示已连接)
ntpq -p
# 查看当前系统时间是否正确
date

如果ntpq -p的reach列显示非0(比如377),说明NTP已经正常连接同步了。

4. 检查并设置正确时区

确保时区配置正确,避免时间显示偏差:

# 列出所有可用时区,找到你所在的时区(比如Asia/Shanghai)
timedatectl list-timezones
# 设置时区
timedatectl set-timezone Asia/Shanghai
# 验证时区设置
timedatectl

5. 确保NTP服务开机自启

让NTP服务在系统启动时自动运行,避免下次开机时间又出错:

systemctl enable ntp

补充:改用systemd-timesyncd(Debian 11默认推荐)

如果ntpd不好用,Debian 11默认支持systemd-timesyncd,配置更简单:

# 停止并禁用ntpd
systemctl stop ntp
systemctl disable ntp
# 启用并启动systemd-timesyncd
systemctl enable --now systemd-timesyncd
# 查看同步状态
timedatectl show-timesync --all

你也可以编辑/etc/systemd/timesyncd.conf,添加阿里云的NTP服务器:

[Time]
NTP=ntp.aliyun.com
FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org

修改后重启服务:systemctl restart systemd-timesyncd

最后验证apt问题

时间同步正确后,再运行apt update,证书验证失败的问题应该就消失了。

内容的提问来源于stack exchange,提问作者CheverJohn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 08:57:47