🔑
blog.cat.ssl

Lost or leaked SSL private key: what to do

22.11.2026
← All articles

Every SSL certificate comes as a pair: the certificate itself, which is public, and the private key, which lives only on the server. Anyone can copy your certificate from a browser; that's harmless. The private key, however, is the seal that proves your site's identity. Two kinds of accidents happen to it: the key is lost, or the key is exposed. They look similar but call for very different responses.

The key is lost: no reason to panic

The server was reinstalled, a disk failed, or the certificate was ordered on another machine and the key file wasn't kept. Without the key, the web server cannot use the certificate. If nobody else ever had the key, though, nothing has been compromised. Simply create a new key and get a new certificate for it. With Let's Encrypt this takes minutes; paid certificates can usually be reissued against a new CSR, sometimes at no extra cost, so check your vendor's terms. If you are confident no copy survives anywhere, revoking the old certificate is not required.

openssl req -new -newkey rsa:2048 -nodes \
  -keyout example.uz.key -out example.uz.csr -subj "/CN=example.uz"
chmod 600 example.uz.key

The key leaked: this is a security incident

Exposure means the key ended up somewhere an outsider could see it: pushed to a public Git repository, left in a downloadable backup.zip in the web root, pasted into Telegram or email, or taken from a hacked server. You can't know who saw it, so assume the worst. An attacker holding the key could, for example, serve a fake version of your site on public Wi-Fi without any browser warning. A new certificate alone is not enough; the old one must be revoked.

  1. Close the source. Remove the file, delete exposed backups, change compromised passwords. Purging Git history is a separate job; a plain delete leaves the key in old commits.
  2. Create a new key. Never reuse the old one.
  3. Issue and install a new certificate, reload the web server and test.
  4. Revoke the old certificate with reason keycompromise.
  5. Rotate neighbouring secrets: database passwords, API keys and SSH keys that may have leaked alongside.
sudo certbot renew --cert-name example.uz --force-renewal
sudo systemctl reload nginx
sudo certbot revoke --cert-path /root/old/cert.pem --reason keycompromise

Certbot normally generates a fresh key on each renewal, but reuse_key = True in its config keeps the old one, so make sure it's off. Copy the old certificate file aside before reissuing so you can revoke it afterwards.

Checking that a key matches a certificate

openssl x509 -in example.uz.crt -noout -pubkey | openssl sha256
openssl pkey -in example.uz.key -pubout | openssl sha256

Matching hashes mean a correct pair. This works for RSA and ECDSA alike, and a "key values mismatch" error from the web server usually points to the wrong pair.

Example: a school site and a public GitHub repo

A student built the website of a private school in Fergana, misol.uz, and published the code on GitHub as a portfolio project, including an ssl/ folder with the certificate and private key. Bots that scan public repositories find such files quickly, so the key must be treated as compromised from the moment of upload. The administrator made the repo private, purged the folder from Git history, issued a certificate with a new key, revoked the old one and added *.key and *.pem to .gitignore. On sayt.uz hosting with automatic Let's Encrypt, asking support to reissue and revoke would have been enough.

Habits that prevent the next leak

Keep the private key on the server: never send it via chat, email or shared documents, and give developers their own SSH access instead. Store it outside the web root, readable only by the web server. Encrypt backups and keep them out of the site folder. Prefer short-lived, auto-renewing certificates so any exposure window stays small, and enable a secret scanner such as gitleaks to catch mistakes before they are pushed.

Related articles

🐳 Automatic SSL in Docker with Traefik: A Complete Setup 🔍 CT Logs Reveal Your Subdomains: The Risk of "Hidden" Test Sites ✳️ Automating wildcard SSL with DNS-01: a Certbot and acme.sh guide 🪪 Client Certificate Login: An Extra Lock for Your Admin Panel
🌐 Language
🇺🇿 O⁠'zbek 🇺🇿 Özbek (yangi) 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓