The error occurs when a server presents a self-signed certificate, and the client does not trust it because there is no certificate authority (CA) verifying it.
Common Causes:
Run:
openssl s_client -connect yourdomain.com:443 -showcerts
Expected output (if self-signed):
verify error:num=18:self-signed certificate
verify return:1
verify error:num=19:self-signed certificate in certificate chain
verify return:1
If you see depth=0, it means the certificate is not trusted.
Solution: Add the certificate to the system's trusted store.
sudo cp your_certificate.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
sudo cp your_certificate.crt /etc/pki/ca-trust/source/anchors/
sudo update-ca-trust
Restart your server:
sudo systemctl restart apache2
or
sudo systemctl restart nginx
Run:
curl -k https://yourdomain.com
-k or --insecure tells curl to ignore SSL verification.
Set:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
Not recommended for production (security risk).
If you see:
fatal: unable to access 'https://yourdomain.com/repo.git/': SSL certificate problem: self signed certificate
Run:
git config --global http.sslVerify false
or add the certificate manually:
git config --global http.sslCAInfo /path/to/certificate.crt
Instead of using a self-signed certificate, get a free SSL certificate from Let's Encrypt.
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx
| Issue | Fix |
|---|---|
| Self-signed certificate error | Add certificate to trusted store (update-ca-certificates) |
| Ignoring self-signed cert in curl | Use curl -k |
| Ignoring self-signed cert in Git | Use git config --global http.sslVerify false |
| Get a valid certificate | Use Let's Encrypt with certbot |
Now you know how to fix depth_zero_self_signed_cert for different scenarios!