Unable to get local issuer certificate: error 20 by depth
By Mara Voss · Self-Hosting & Network Security · Last verified 2026-11-11
curl: (60) SSL certificate problem: unable to get local issuer certificate almost never means the certificate you bought is broken. It means one link of the chain between the leaf certificate and a root your client already trusts is missing, and OpenSSL cannot find the issuer for the certificate it is currently looking at. The link can be missing on the server, in the file nginx or Caddy was handed, or in the client's trust store. Both cases print the same sentence.
The number that separates them is the depth= field printed by openssl s_client, and it is the first thing to read. Below is a lab built from one root, one intermediate and one leaf on OpenSSL 3.5.7, with four different clients pointed at the same server. Every output quoted here was produced by that run on 2026-11-11 and pasted unchanged.
The certificate is almost never the problem
OpenSSL verifies a chain by walking upward from the leaf: leaf, then its issuer, then that issuer's issuer, until it reaches a certificate that is present in the trust store. Error 20 is emitted at the moment that walk stops because the next certificate is not available anywhere — not on the wire, not in the file, not in the trust store. The leaf itself can be perfectly valid, correctly signed, unexpired and matched to the hostname while the handshake still fails with error 20.
That is why "regenerate the certificate" and "renew the certificate" are the two fixes that so reliably waste an afternoon. The certificate is usually the one thing in the chain that is working. What is missing is the intermediate CA certificate — the object a public CA signs your leaf with but does not put inside the leaf.
There are exactly two failure shapes, and they produce different depths:
- depth=0: the issuer of the leaf is not being sent by the server. The client has no way to even start the walk. Nothing you add to the client's trust store will help, because the missing object is not a root, it is an intermediate the client has never seen.
- depth=1 (or deeper): the server is sending the intermediate, and the walk failed one level higher. Now the missing object is a root, and the fix is on the client side: the trust store does not contain the CA that signed the intermediate.
Read the depth before you change anything
One command shows both the depth and the code, on the real listener, with the real SNI. It is the only measurement worth taking first:
echo | openssl s_client -connect 127.0.0.1:8449 -servername localhost \
-CAfile /etc/ssl/certs/ca-certificates.crt 2>&1 \
| grep -E 'depth=|verify error|Verify return code'
Against a server that sends the leaf certificate only, that prints:
depth=0 CN=localhost
verify error:num=20:unable to get local issuer certificate
depth=0 CN=localhost
verify error:num=21:unable to verify the first certificate
depth=0 CN=localhost
Verify return code: 21 (unable to verify the first certificate)
Two codes for one handshake, and the final line is the other one. s_client runs the verification callback twice; the second pass has already given up on the leaf, so it reports 21, "unable to verify the first certificate". The reason the same failure appears in curl as error 20 and here as error 21 is that they are different messages from the same broken walk — curl quotes the first failure, s_client's summary line quotes the last. Do not treat 20 and 21 as separate bugs; treat them as the same missing link seen from two angles, and use the depth= line to decide which link.
Set against a server that does send the intermediate, with a client that does not trust the root, the same command shows the depth move up by exactly one:
depth=1 CN=c2cz Lab Intermediate CA
verify error:num=20:unable to get local issuer certificate
depth=0 CN=localhost
Verify return code: 20 (unable to get local issuer certificate)
Same code, different depth, opposite fix. Depth 0 means "fix what the server sends". Depth 1 means "fix what the client trusts". Everything below is the mechanics of those two sentences, plus the third mistake that produces a completely different error and confuses people the most.
Build the three-level chain so the failure is reproducible
A lab of three certificates is enough to reproduce every error in this article, and it takes a few seconds. The root is the only thing a client store would ever hold; the intermediate is the object that goes missing; the leaf is what the server actually serves.
openssl req -x509 -newkey rsa:2048 -nodes -keyout root.key -out root.pem -days 30 \
-subj "/CN=c2cz Lab Root CA" -addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,keyCertSign,cRLSign"
openssl req -newkey rsa:2048 -nodes -keyout int.key -out int.csr \
-subj "/CN=c2cz Lab Intermediate CA"
printf 'basicConstraints=critical,CA:TRUE,pathlen:0\nkeyUsage=critical,keyCertSign,cRLSign\nsubjectKeyIdentifier=hash\nauthorityKeyIdentifier=keyid\n' > int.ext
openssl x509 -req -in int.csr -CA root.pem -CAkey root.key -CAcreateserial \
-out int.pem -days 25 -extfile int.ext
openssl req -newkey rsa:2048 -nodes -keyout leaf.key -out leaf.csr -subj "/CN=localhost"
printf 'basicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth\nsubjectAltName=DNS:localhost,IP:127.0.0.1\nauthorityKeyIdentifier=keyid\n' > leaf.ext
openssl x509 -req -in leaf.csr -CA int.pem -CAkey int.key -CAcreateserial \
-out leaf.pem -days 20 -extfile leaf.ext
cat leaf.pem int.pem > fullchain.pem
The consequence of that last line is the whole article: fullchain.pem contains two certificates, leaf.pem contains one, and both have the same public key. Confirming that the files differ only in length is worth ten seconds:
grep -c 'BEGIN CERTIFICATE' fullchain.pem reversed.pem everything.pem
fullchain.pem:2
reversed.pem:2
everything.pem:3
everything.pem was made by concatenating leaf, intermediate and root, which is a mistake with its own error code, covered further down.
Case 1: depth=0 means the server is not sending the intermediate
Point a TLS server at leaf.pem and the handshake fails for a client that trusts the root perfectly well. Verified offline, with no network involved at all:
openssl verify -CAfile root.pem leaf.pem
CN=localhost
error 20 at 0 depth lookup: unable to get local issuer certificate
error leaf.pem: verification failed
Now hand the same verifier the intermediate as an untrusted input, which is exactly what a TLS client does when the server sends it:
openssl verify -CAfile root.pem -untrusted fullchain.pem leaf.pem
leaf.pem: OK
Same root, same leaf, same store: the only difference is whether the intermediate was offered. This is the proof that "the certificate is expired" and "the CA is not trusted" are both wrong explanations for case 1. The verifier had the root it needed and still could not verify, because it had no idea who signed the leaf.
The client-side proof is worse-looking and identical in cause. curl with the correct root supplied explicitly still fails against that server:
curl -sS --max-time 5 --cacert root.pem https://localhost:8443/
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the webpage mentioned above.
The exit code is 60 and the message is byte-identical to the version with no --cacert at all. That is the tell: when adding a CA changes nothing, the missing object is not a CA you can add. Python behaves the same way with both environment variables, which is what makes this case so resistant to the usual advice:
SSL_CERT_FILE=$PWD/root.pem python3 client.py 8445
REQUESTS_CA_BUNDLE=$PWD/root.pem python3 client.py 8445
SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1082)
verify_code: 20 verify_message: unable to get local issuer certificate
Two environment variables, both pointing at the right root, both ignored in effect, because the server never sent the intermediate. The (_ssl.c:1082) suffix is the CPython build's line number for the error and changes between versions; do not search for it.
The fix for case 1 is one file on the server. Whatever terminates TLS must be given a bundle that starts with the leaf and continues with every intermediate up to but excluding the root: cat leaf.pem int.pem for a private CA, or the fullchain.pem your ACME client already writes. In nginx that is ssl_certificate pointing at the bundle, never at the leaf alone; ssl_certificate_key stays the leaf key. There is no client-side configuration that repairs this, which is why it is worth checking before touching a trust store.
Case 2: depth=1 means the client does not trust your root
Set against a server that does send the intermediate, with a client whose store does not contain the root, the same command shows the depth move up by exactly one:
echo | openssl s_client -connect 127.0.0.1:8451 -servername localhost \
-CAfile /etc/ssl/certs/ca-certificates.crt 2>&1 \
| grep -E 'depth=|verify error|Verify return code'
depth=1 CN=c2cz Lab Intermediate CA
verify error:num=20:unable to get local issuer certificate
depth=0 CN=localhost
Verify return code: 20 (unable to get local issuer certificate)
Two short probes reproduce the error without curl in the way. client.py takes a port, and nodeclient.js takes the same port as an argument:
import socket, ssl, sys
port = int(sys.argv[1])
ctx = ssl.create_default_context()
try:
with socket.create_connection(("127.0.0.1", port), timeout=5) as s:
with ctx.wrap_socket(s, server_hostname="localhost") as t:
print("handshake ok:", t.version())
except ssl.SSLCertVerificationError as e:
print("SSLCertVerificationError:", e)
print("verify_code:", e.verify_code, "verify_message:", e.verify_message)
const https = require('https');
https.get({host: '127.0.0.1', port: process.argv[2], path: '/', servername: 'localhost',
headers: {host: 'localhost'}}, r => {console.log('status ' + r.statusCode); process.exit(0);})
.on('error', e => {console.log(e.code + ' ' + e.message); process.exit(0);});
The error object carries the same number OpenSSL uses, which is why verify_code: 20 is printed separately from the message: the message text changes between OpenSSL builds, the code does not.
This is the case where the client-side knobs do work, and each client hides its trust store in a different place. Measured against one full-chain server listening on 8451 and one leaf-only server on 8452, in a single run, with the correct root supplied to every client:
curl -sS --max-time 5 --cacert root.pem https://localhost:8451/
SSL_CERT_FILE=$PWD/root.pem python3 client.py 8451
NODE_EXTRA_CA_CERTS=$PWD/root.pem node nodeclient.js 8451
git -c http.sslCAInfo=$PWD/root.pem ls-remote https://localhost:8451/
git -c http.sslCAInfo=$PWD/root.pem ls-remote https://localhost:8452/
ok
handshake ok: TLSv1.3
status 200
fatal: https://localhost:8451/info/refs not valid: is this a git repository?
fatal: unable to access 'https://localhost:8452/': server verification failed: certificate signer not trusted. (CAfile: /tmp/c2cz-verify/issuer20/root.pem CRLfile: none)
The fourth line is a success, which is not obvious: git got an HTTP response and complained about the protocol instead of the certificate, so TLS verification passed. That is what a client-side fix looks like when the server is correct — the failure moves to a different layer. The fifth line is the most misread output in this whole family. It names the right file, (CAfile: .../root.pem CRLfile: none), and still fails, because the server behind that port sends the leaf alone. A CAfile named in a failure message is not evidence that the CAfile is the problem; here it is evidence that the server's bundle is.
Node is worth its own paragraph because it has two distinct codes and most guides quote only one. Against the leaf-only server it prints UNABLE_TO_VERIFY_LEAF_SIGNATURE unable to verify the first certificate, and against the correct bundle with an untrusted root it prints UNABLE_TO_GET_ISSUER_CERT_LOCALLY unable to get local issuer certificate. So the first maps to the server-side problem and the second to the client-side one — the same split as depth 0 versus depth 1, exposed as two error codes instead of one. Node 26 appends a suggestion to the first message, offering --use-system-ca; in this run the same request returned status 200 once NODE_EXTRA_CA_CERTS pointed at the private root. On a Debian host the system bundle held 148 certificates in this run, and none of them is your private root unless someone installed it there.
The third mistake: shipping the root inside the bundle
Concatenating every certificate you have — leaf, intermediate, root — feels safer and breaks clients that the correct bundle satisfies. Take everything.pem, built with cat leaf.pem int.pem root.pem, and serve it. curl accepts it; Node refuses it, on the same server, in the same second:
curl -sS --max-time 5 --cacert root.pem https://localhost:8447/
node nodeclient.js 8447
ok
SELF_SIGNED_CERT_IN_CHAIN self-signed certificate in certificate chain
The server's own view makes the cause obvious — three certificates on the wire, the root included:
0 s:CN=localhost
1 s:CN=c2cz Lab Intermediate CA
2 s:CN=c2cz Lab Root CA
Verify return code: 0 (ok)
OpenSSL itself is happy, which is why this mistake survives staging and dies in production behind a Node or Java client. A root is self-signed by definition; a client that already trusts that root in its store finds a self-signed certificate arriving in the chain and, depending on the implementation, flags it. The rule that prevents it: a served chain ends at the last intermediate, never at the root. The root belongs in trust stores, not in bundles.
One related assumption is worth killing with a measurement. The order inside the bundle does not matter to openssl verify — it matches by issuer and subject, not by position:
openssl verify -CAfile root.pem -untrusted reversed.pem leaf.pem
leaf.pem: OK
reversed.pem holds the intermediate before the leaf and verifies fine. That does not make order irrelevant on the wire: TLS expects the sender's own certificate first, and several server implementations will simply fail to load a bundle whose first certificate does not match the private key. If a server refuses to start after you edited the bundle, check the first certificate against the key before you check anything else.
Match the link by hand when the messages disagree
When one client says error 20 at depth 0 and another says "signer not trusted", stop reading messages and compare two fields directly. The leaf carries an Authority Key Identifier; the candidate intermediate carries a Subject Key Identifier. If they are the same bytes, the intermediate is the right issuer:
openssl x509 -in leaf.pem -noout -ext authorityKeyIdentifier
openssl x509 -in int.pem -noout -ext subjectKeyIdentifier
X509v3 Authority Key Identifier:
7A:45:9C:70:EC:B6:18:B9:63:E1:40:5F:DA:28:F0:B3:FE:E8:A6:17
X509v3 Subject Key Identifier:
7A:45:9C:70:EC:B6:18:B9:63:E1:40:5F:DA:28:F0:B3:FE:E8:A6:17
Do not substitute the certificate fingerprints for this test. The intermediate's own SHA-256 fingerprint in this lab is AE:45:4A:F8:…, which has no reason to equal anything on the leaf and will send you looking for a problem that does not exist. The key identifiers match because they are derived from the same public key; fingerprints are derived from the whole certificate, including the signature, and never match across two different certificates.
Two more checks settle the questions that error 20 tends to raise, and neither needs a network connection:
openssl x509 -in leaf.pem -noout -checkend 0
openssl x509 -in leaf.pem -noout -checkend 2592000
openssl verify -CAfile trust.pem -untrusted fullchain.pem -verify_hostname example.com leaf.pem
Certificate will not expire
Certificate will expire
CN=localhost
error 62 at 0 depth lookup: hostname mismatch
error leaf.pem: verification failed
-checkend 0 exits 0 when the certificate is still valid and -checkend 2592000 exits 1 when it expires inside 30 days, so the same command becomes a monitoring check with a meaningful exit status. The hostname test returns error 62, not 20, which is the useful part: if your failure number is 62 you are looking at the wrong field entirely, and no amount of chain repair will change it.
What not to do, and why it hides the problem
Every one of the failures above can be silenced in one flag or one argument. curl -k, requests.get(url, verify=False), NODE_TLS_REJECT_UNAUTHORIZED=0 and git -c http.sslVerify=false all turn a verification failure into a successful connection with no authentication of the peer. That is not a fix, it is the removal of the check that the connection depends on, and it converts a loud error into a silent exposure. The reason to care here is diagnostic rather than moral: once verification is off, the depth line disappears, and the same server will fail again the moment a client that does check connects — a health probe, a cron job, a package manager, a browser.
The other anti-fix is copying a random root into a trust store to make a message go away. In case 1 that does nothing measurable (the root was already correct and the handshake still fails, as shown above), and in case 3 it is the exact condition that produced SELF_SIGNED_CERT_IN_CHAIN. Trust stores are an allowlist of who may sign for you; adding to them is a decision about which CAs can impersonate the host, not a troubleshooting step.
The triage order that actually converges
Three measurements, in this order, end the ambiguity in under a minute:
echo | openssl s_client -connect host:443 -servername host -CAfile /etc/ssl/certs/ca-certificates.crtand readdepth=. Depth 0 sends you to the served bundle; depth 1 sends you to the client's store. Both print error 20, so the depth is the only useful field.openssl crl2pkcs7 -nocrl -certfile bundle.pem | openssl pkcs7 -print_certs -nooutshows what the server is really sending, in order, with subjects and issuers. If only one certificate is listed, the intermediate is missing and no client change will help.openssl verify -CAfile root.pem -untrusted bundle.pem leaf.pemreproduces the client's decision offline, in milliseconds, without touching the running service. If it saysOKwhile the client still fails, the bundle is right and the client's store is wrong.
That last inversion is the one that saves the most time: a green offline verify on the exact file the server serves moves the entire investigation to the client, and a red one moves it entirely to the server. Error 20 is a single sentence doing the work of two different bugs, and the depth number is the only thing in the output that tells them apart. Once the depth is known, the fix is a one-line change in a file you can name — the served bundle, or the trust store of the specific client that is complaining.
For the neighbouring failure class, where the TLS handshake dies mid-stream rather than at verification, error:0A000126 unexpected eof while reading covers the origin side. If the question is trust establishment for a different protocol, Host key verification failed: six causes, one test applies the same depth-first discipline to SSH.
Entire lab run on OpenSSL 3.5.7, curl 8.14.1 (libcurl/8.14.1 OpenSSL/3.5.7), Node v26.12.1 and git 2.47.3 on 2026-11-11. Every transcript above is from that single run; the private PKI, the four servers and the client scripts were generated in one directory and removed afterwards.