Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

apt update fails on an HTTPS repository with Certificate verification failed

Your error

Could not handshake: Error in the certificate verification.1 more line it can show

Fix it fast

Most common cause, 1 of 2

The ca-certificates package is not installed

Install ca-certificates while only the distribution's default sources are enabled, then add the HTTPS repository.

Fix
sudo mv /etc/apt/sources.list.d/repo.list /root/repo.list.off
sudo apt-get update && sudo apt-get install -y ca-certificates
sudo mv /root/repo.list.off /etc/apt/sources.list.d/repo.list
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Certificate verification failed and Could not handshake: Error in the certificate verification mean apt on Ubuntu 24.04 could not trust an HTTPS repository's certificate. apt checks it against the system store from the ca-certificates package. Install ca-certificates before adding HTTPS sources, add a proxy or private CA through update-ca-certificates, or set Acquire::https::CAInfo for that host.

  • Applies to apt 2.7, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

See which source fails, whether the CA store exists at all, and who issued the certificate the repository presents. A missing store points to the first cause; an issuer that is not a public CA points to the second.

Run this first
sudo apt-get update 2>&1 | grep -B1 -E "Certificate verification failed|Could not handshake"
dpkg -s ca-certificates | grep Status
ls -l /etc/ssl/certs/ca-certificates.crt
openssl s_client -connect repo.example.com:443 -servername repo.example.com </dev/null 2>/dev/null | openssl x509 -noout -issuer

Then find the line you see in this list and open its fix:

  1. 1The ca-certificates package is not installeddpkg -s reports ca-certificates as not installed, or /etc/ssl/certs/ca-certificates.crt does not exist, typically in a minimal container image
  2. 2A proxy or private mirror uses a CA the system does not trustOnly one repository fails, or every source fails only behind the office network, and the issuer printed by s_client is your company or proxy CA

What does the error look like?

  • Could not handshake: Error in the certificate verification.
  • Certificate verification failed: (followed by the GnuTLS reason, on the line before Could not handshake)

Cause 1 of 2

The ca-certificates package is not installed

You seedpkg -s reports ca-certificates as not installed, or /etc/ssl/certs/ca-certificates.crt does not exist, typically in a minimal container image

Check

Certificate verification failed for every HTTPS source at once usually means the system has no CA store, because ca-certificates is missing. apt's HTTPS method verifies servers against all certificates the system trusts through that package, so without it no public CA is trusted either.

Check
dpkg -s ca-certificates | grep Status

Fix

Install ca-certificates while only the distribution's default sources are enabled, then add the HTTPS repository. Docker's Ubuntu install guide uses exactly this order. If the HTTPS source is already configured, move its file out of /etc/apt/sources.list.d for the install and back afterwards.

Fix
sudo mv /etc/apt/sources.list.d/repo.list /root/repo.list.off
sudo apt-get update && sudo apt-get install -y ca-certificates
sudo mv /root/repo.list.off /etc/apt/sources.list.d/repo.list

Verify

The bundle exists and apt-get update fetches the HTTPS source.

Verify
ls -l /etc/ssl/certs/ca-certificates.crt
sudo apt-get update

Confirmed by manpages.ubuntu.com

Did this fix it?

Cause 2 of 2

A proxy or private mirror uses a CA the system does not trust

You seeOnly one repository fails, or every source fails only behind the office network, and the issuer printed by s_client is your company or proxy CA

Check

Could not handshake: Error in the certificate verification for one mirror, or only behind a corporate network, means the certificate was issued by a private or TLS-inspection CA that is not in the system store. Public repositories pass, so the store itself works.

Check
openssl s_client -connect repo.example.com:443 -servername repo.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer

Fix

Get the root certificate in PEM form from whoever runs the proxy or mirror. To trust it system-wide, save it with a .crt name in /usr/local/share/ca-certificates and run update-ca-certificates. To trust it for apt and one host only, point the host-specific CAInfo option at the file.

Fix
# system-wide
sudo cp company-root.pem /usr/local/share/ca-certificates/company-root.crt
sudo update-ca-certificates

# or apt only, one host: /etc/apt/apt.conf.d/80repo-ca
Acquire::https::CAInfo::repo.example.com "/etc/apt/certs/company-root.pem";

Verify

update-ca-certificates finishes without an error, and apt-get update reads the source cleanly.

Verify
sudo apt-get update

Confirmed by manpages.ubuntu.com

Did this fix it?

How do I stop it coming back?

  • Put apt-get install ca-certificates in the Dockerfile before any step that adds an HTTPS repository.
  • Ship the company root CA in the base image and run update-ca-certificates there, so every container trusts the proxy from the start.
  • Scope any CA override to the one repository host with the ::host form, instead of a global Acquire::https setting.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.