GrepBoard/Manuals
605 manuals ·

Fix curl: (60) unable to get local issuer certificate

·Tested on nginx 1.30.6 · curl 8.17.0 · curl 8.5.0 (Ubuntu 24.04) (Docker) · 2026-10·Test scope ↓·6 steps

curl (60) unable to get local issuer certificate: the server skipped its intermediate certificate or the root isn't in your CA bundle. Fix it without -k.

output
curl: (60) SSL certificate problem: unable to get local issuer certificateMore details here: https://curl.se/docs/sslcerts.html

curl could not build a chain from the server certificate up to a root CA it trusts. There are two causes: the server didn't send the intermediate certificate, or the chain arrived complete but its root isn't in curl's CA bundle (a private or corporate CA). -k fixes neither; it only turns verification off.

curl 8.17 prints the same error with the OpenSSL verify code. Both forms are the same problem:

output
curl: (60) SSL certificate OpenSSL verify result: unable to get local issuer certificate (20)

[1] Check how many certificates the server sends. Below, nginx's ssl_certificate holds only the server certificate; -CAfile gets the test root.

console
$ openssl s_client -connect 127.0.0.1:8443 -servername app.example.com -showcerts -CAfile root.pem </dev/null 2>/dev/null | grep -E "^ *[0-9] s:|^ *i:|Verify return code" 0 s:CN=app.example.com   i:CN=Test Intermediate CAVerify return code: 21 (unable to verify the first certificate)

There is only certificate 0; its issuer (i:), Test Intermediate CA, never arrives. Even with the root trusted, the missing middle link ends in 21. If you see this, go to [2]. If certificates 0 and 1 both arrive and it still fails, go to [3]. The public test host incomplete-chain.badssl.com looks the same (one certificate) and gives curl the same (60).

[2] Add the intermediate on the server. As the nginx docs describe, put the server certificate first, then the CA's intermediate bundle, in one file and point ssl_certificate at it.

console
$ cat leaf.pem inter.pem > fullchain.pem
/etc/nginx/conf.d/app.conf
server {    listen 8444 ssl;    server_name app.example.com;  ssl_certificate     /certs/fullchain.pem;    ssl_certificate_key /certs/leaf.key;}

In the wrong order, nginx refuses to start with key values mismatch, per its docs (nginx key values mismatch). Copy the current certificate file before you change anything; to roll back, restore it, run nginx -t, and reload. With certbot, point at fullchain.pem, not cert.pem (server certificate only) — the certbot docs name fullchain.pem as the file for nginx ssl_certificate.

After the change, two certificates arrive and verification ends in 0:

console
$ openssl s_client -connect 127.0.0.1:8444 -servername app.example.com -showcerts -CAfile root.pem </dev/null 2>/dev/null | grep -E "^ *[0-9] s:|^ *i:|Verify return code" 0 s:CN=app.example.com   i:CN=Test Intermediate CA 1 s:CN=Test Intermediate CA   i:CN=Test Root CAVerify return code: 0 (ok)$ curl -sS --resolve app.example.com:8444:127.0.0.1 https://app.example.com:8444/ --cacert root.pem; echo exit=$?okexit=0

The nginx docs note that browsers often cache intermediates they've seen and hide this problem. "Works in the browser, fails in curl" usually lands here.

[3] If the full chain arrives and curl still fails, check which CA bundle curl reads. The same two-certificate server fails again without --cacert, because the private root isn't in the system bundle:

console
$ curl -sS --resolve app.example.com:8444:127.0.0.1 https://app.example.com:8444/; echo exit=$?curl: (60) SSL certificate OpenSSL verify result: unable to get local issuer certificate (20)…exit=60$ curl -v --resolve app.example.com:8443:127.0.0.1 https://app.example.com:8443/ -o /dev/null 2>&1 | grep -iE 'CAfile|CApath'*  CAfile: /etc/ssl/certs/ca-certificates.crt*  CApath: /etc/ssl/certs

(The CAfile lines are from curl 8.5.0 on Ubuntu 24.04.) The fix is to trust the root:

  • One command: --cacert root.pem, or the CURL_CA_BUNDLE environment variable (curl's docs also list SSL_CERT_FILE and SSL_CERT_DIR).
  • System-wide on Ubuntu: copy the PEM certificate into /usr/local/share/ca-certificates/ **with a .crt extension** and run sudo update-ca-certificates. Other extensions are ignored. To undo, delete the file and run sudo update-ca-certificates --fresh; in testing, a plain run reported 0 added, 0 removed and left a dangling link in /etc/ssl/certs.
  • In a container, check first that the image has the ca-certificates package.

[4] If it's someone else's server and you can't do [2], you can work around it on the client by adding the intermediate to your bundle. Here the one-certificate server on 8443 passes with root and intermediate in one file (curl 8.5.0 on Ubuntu 24.04):

console
$ cat root.pem inter.pem > root-plus-inter.pem$ curl -sS --resolve app.example.com:8443:127.0.0.1 https://app.example.com:8443/ --cacert root-plus-inter.pem -o /dev/null -w 'HTTP %{http_code}\n'; echo "exit=$?"HTTP 200exit=0

[5] A slightly different message means a different cause.

MessageMeaning
unable to get local issuer certificateIntermediate missing, or root not in the CA bundle
self-signed certificate in certificate chainThe server (or a TLS-inspecting corporate proxy) sent the root, but you don't trust it — add that root as in [3]
self-signed certificateA single certificate signed by itself — see self-signed certificate test
curl: (77) error setting certificate file: …Wrong --cacert or CURL_CA_BUNDLE path (fails before verification)

[6] Don't get past it with -k (--insecure). In testing, -k happily returned ok from the one-certificate server — it can't tell a broken chain from an impostor. curl's docs strongly recommend never skipping verification in production.

If curl works but pip fails with CERTIFICATE_VERIFY_FAILED behind the same corporate proxy or private index, pip's own CA settings are the place to look — see Fix pip SSL: CERTIFICATE_VERIFY_FAILED.

Analyze your Nginx log in the browser ↗ — nothing is uploaded.

Check it with the Certificate (PEM · X.509) decoder tool ↗ — calculated in your browser.

#curl#tls#certificate-chain#intermediate-certificate#nginx