Debian

我如何強制 apt-get 或 apt 僅使用 https 連接

  • September 28, 2021

我在僅使用 https 的網路上執行 mongo db docker 容器。容器使用 apt-get 來安裝包。由於網路只允許 https 連接,apt-get 對我不起作用。在安裝 apt-transport-https 後,我嘗試在 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中使用 https 更改 http。但沒有什麼對我有用。這是我用 https 替換 https 後的 /etc/apt/sources.list

deb https://deb.debian.org/debian jessie main
deb https://security.debian.org/debian-security jessie/updates main
deb https://deb.debian.org/debian jessie-updates main

/etc/apt/sources.list.d 中的 mongodb-org.list 文件看起來像

deb https://repo.mongodb.org/apt/debian jessie/mongodb-org/3.2 main

在完成所有這些 apt-get update 顯示之後

Get:1 https://repo.mongodb.org jessie/mongodb-org/3.2 InRelease [384 B]
Ign https://repo.mongodb.org jessie/mongodb-org/3.2 InRelease
Get:2 https://repo.mongodb.org jessie/mongodb-org/3.2 Release.gpg [801 B]
Hit https://repo.mongodb.org jessie/mongodb-org/3.2 Release
Get:3 https://deb.debian.org jessie InRelease [309 B]
Ign https://deb.debian.org jessie InRelease
Hit https://deb.debian.org jessie-updates InRelease
Ign https://security.debian.org jessie/updates InRelease
Ign https://repo.mongodb.org jessie/mongodb-org/3.2 Release
Get:4 https://repo.mongodb.org jessie/mongodb-org/3.2/main amd64 Packages [10.6 kB]
Hit https://deb.debian.org jessie Release.gpg
Ign https://security.debian.org jessie/updates Release.gpg
Ign https://security.debian.org jessie/updates Release
Get:5 https://deb.debian.org jessie-updates/main amd64 Packages [337 B]
Err https://security.debian.org jessie/updates/main amd64 Packages

Hit https://deb.debian.org jessie Release
Err https://security.debian.org jessie/updates/main amd64 Packages

Err https://security.debian.org jessie/updates/main amd64 Packages

Get:6 https://deb.debian.org jessie/main amd64 Packages [329 B]
Err https://security.debian.org jessie/updates/main amd64 Packages

Err https://security.debian.org jessie/updates/main amd64 Packages
 server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
Fetched 9110 kB in 8s (1096 kB/s)
W: GPG error: https://repo.mongodb.org jessie/mongodb-org/3.2 Release: The following signatures were invalid: KEYEXPIRED 1570654450
W: Size of file /var/lib/apt/lists/partial/deb.debian.org_debian_dists_jessie-updates_main_binary-amd64_Packages.gz is not what the server reported 20 337
W: Failed to fetch https://security.debian.org/debian-security/dists/jessie/updates/main/binary-amd64/Packages  server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

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

無法從 https 連接中檢索安全更新,在debian上進行了解釋

主機目前security.debian.org在 HTTPS 上沒有可公開驗證的 SSL 證書,因此目前不能與 HTTPS 一起使用。

您可以編輯/etc/apt/sources.list如下:

deb https://deb.debian.org/debian jessie main
deb http://security.debian.org/debian-security jessie/updates main
deb https://deb.debian.org/debian jessie-updates main

要解決 MongoDB 的 gpg 密鑰錯誤,您應該更新 gpg 密鑰,請參閱我導入包管理系統使用的公鑰

wget -qO - https://www.mongodb.org/static/pgp/server-3.2.asc | sudo apt-key add -

引用自:https://unix.stackexchange.com/questions/552934