Ubuntu 22.04更新apt出现The certificate issuer is unknown的解决办法
问题描述
使用docker安装Ubuntu22.04,官网给出的镜像只是一个裸系统,预装软件很少。换阿里源以后,apt update
,出现如下报错:
shell
# apt update
Ign:1 https://mirrors.aliyun.com/ubuntu-ports jammy InRelease
Ign:2 https://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease
Ign:3 https://mirrors.aliyun.com/ubuntu-ports jammy-updates InRelease
Ign:4 https://mirrors.aliyun.com/ubuntu-ports jammy-backports InRelease
Ign:1 https://mirrors.aliyun.com/ubuntu-ports jammy InRelease
Ign:2 https://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease
Ign:3 https://mirrors.aliyun.com/ubuntu-ports jammy-updates InRelease
Ign:4 https://mirrors.aliyun.com/ubuntu-ports jammy-backports InRelease
Ign:1 https://mirrors.aliyun.com/ubuntu-ports jammy InRelease
Ign:2 https://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease
Ign:3 https://mirrors.aliyun.com/ubuntu-ports jammy-updates InRelease
Ign:4 https://mirrors.aliyun.com/ubuntu-ports jammy-backports InRelease
Err:1 https://mirrors.aliyun.com/ubuntu-ports jammy InRelease
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 222.192.186.76 443]
Err:2 https://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 222.192.186.77 443]
Err:3 https://mirrors.aliyun.com/ubuntu-ports jammy-updates InRelease
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 222.192.186.76 443]
Err:4 https://mirrors.aliyun.com/ubuntu-ports jammy-backports InRelease
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 222.192.186.77 443]
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-security/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-updates/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-backports/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-security/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-updates/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-backports/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-security/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-updates/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-backports/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-security/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-updates/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-backports/InRelease: No system certificates available. Try installing ca-certificates.
W: Failed to fetch https://mirrors.aliyun.com/ubuntu-ports/dists/jammy/InRelease Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 222.192.186.76 443]
W: Failed to fetch https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-security/InRelease Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 222.192.186.77 443]
W: Failed to fetch https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-updates/InRelease Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 222.192.186.76 443]
W: Failed to fetch https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-backports/InRelease Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 222.192.186.77 443]
W: Some index files failed to download. They have been ignored, or old ones used instead.
重点出在了The certificate issuer is unknown.
上,这个错误通常表示 SSL/TLS 证书的颁发机构未知或无法验证。网上给出的方法有很多,但是或多或少都要用到一些需要安装的工具,而裸系统上都没有。
解决办法
- 改
https
为http
。以阿里云镜像为例,直接将以下脚本拷贝到终端运行,将apt
配置写入/etc/apt/sources.list
。
sh
# 清空当前 sources.list
bash -c 'echo "" > /etc/apt/sources.list'
# 写入新的源列表
tee /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
# deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
EOF
- 运行
apt update
。问题解决,成功更新。 - 考虑到
http
终归不安全,安装证书并更新。
sh
apt install ca-certificates
update-ca-certificates
然后,将/etc/apt/sources.list
中http
改回https
。
讨论
- 换源时要去官方站点,CSDN博主分享的一些配置文件可能已经失效。官方站点中应有尽有,例如阿里云的站点。
- 在没有
vim
等编辑器的情况下,可以借鉴上文笔者的方法,使用命令行的方式编辑文件。