Public Key and Private Key in SSL: What They Are and How to Protect Them
Every SSL certificate depends on a key pair. See what the public and private key do, why the private key must stay secret, and what to do if it leaks.
9 min readUpdated Nov 20, 2026By XPASS Editorial Team

Behind every padlock in the browser there is a pair of mathematical keys. One is public and one is private, and together they make HTTPS possible. Most site owners never see them, because a hosting panel or a certificate tool creates them in the background. That convenience is fine until something goes wrong: a server is migrated, a certificate has to be reissued, or a developer asks "where is the private key?" and nobody knows.
This article explains the two keys in everyday language. You will learn what each key does, how they cooperate when a visitor opens your site, where the private key should live, and how to react if it is exposed. Understanding this also makes the rest of the ordering process easier, including the certificate signing request and the choice of protocol version described in TLS 1.2 vs TLS 1.3.
The idea of a key pair
Older encryption used a single shared secret: whoever knew the secret could both lock and unlock a message. That works for two people who can meet in person, but it is awkward for a stranger visiting a web site, because you would first need a safe way to hand over the secret.
Public-key cryptography solves this with two linked keys. They are generated together and are mathematically related, but you cannot work out the private key from the public key in any practical amount of time when the key size is adequate. What one key does, only the other can undo. In practice, two uses matter:
- Encryption: something locked with the public key can be unlocked only by the private key.
- Digital signature: something signed with the private key can be verified by anyone who has the public key, which proves the signer holds the private key.
A mailbox is a common comparison. Anyone can drop a letter through the slot (the public part), but only the owner with the key can open the box and read what is inside (the private part). The comparison is not perfect, but it shows why the public key can be shared widely.

What the public key does in an SSL certificate
An SSL certificate is a digital document in the X.509 format. It contains the domain names it covers, the validity dates, the name of the issuer, and the public key of the site. The certificate authority adds a signature over all this data, which is how a browser can tell that nobody altered it. The public key is not hidden: it is sent to every visitor at the start of each connection.
The public key has two jobs in the connection. First, it identifies the site: it is the key that the site must prove it owns. Second, it supports the key agreement that creates the secret session keys. In modern TLS the actual traffic is protected by fast symmetric session keys, and the key pair is used to prove identity and to set those session keys up, not to encrypt every web page itself.
What the private key does
The private key is the secret half. On the server it is used to prove, during the handshake, that the server really owns the public key in the certificate. In TLS 1.3 the server signs a part of the handshake transcript with the private key, and the browser checks that signature with the public key from the certificate. A copy of the certificate alone is useless to an impostor, because they cannot produce a valid signature without the private key.
This is why the private key is the real asset. The certificate is public by design; anybody can download it. The private key is the thing that turns "someone with a copy of the certificate" into "the server that owns it". If a third party obtains it, they can impersonate your site to anyone who trusts the certificate until it expires or is revoked.
How the two keys work together when someone visits
Here is the sequence in plain steps:
- The browser connects to your domain and says which TLS versions and cipher suites it supports.
- The server answers with its certificate, including the public key and the chain of issuers.
- The browser checks the certificate: is the name right, is the date valid, is it signed by an authority it trusts.
- The server proves that it holds the private key by signing handshake data. The browser verifies that signature with the public key.
- Both sides derive fresh session keys through a key exchange. Because the exchange uses temporary values, past sessions stay protected even if the long-term private key is stolen later. That property is called forward secrecy and is standard in TLS 1.3.
- From now on, traffic is encrypted with the symmetric session keys.
Notice that the private key never travels over the network. Only the public key and signatures do. If someone ever asks you to email a private key, treat it as a red flag.
RSA and ECDSA: key types and sizes
Two families of key are common for certificates.
| Property | RSA | ECDSA (elliptic curve) |
|---|---|---|
| Typical size today | 2048-bit or larger | 256-bit curve such as P-256 |
| Compatibility | Almost every client | Very wide, with rare very old exceptions |
| Computation cost | Heavier signing, larger keys | Lighter, smaller keys and signatures |
| Common usage | Default in many panels | Increasingly offered as an option |
For most websites either choice is acceptable when the size is adequate. RSA with 2048 bits is a widely used baseline, and the CA/Browser Forum rules set minimum requirements for publicly trusted certificates. Choose the type your server software and your certificate order form support, and avoid keys that are shorter than the minimum. If you are unsure, the default offered by a reputable control panel is normally a sound start. Some operators install both types on one site so that very old clients still have an RSA option.
Where to store the private key
The way you store the key determines how much damage a break-in can do. Follow these habits:
- Generate it where it will be used. Creating the key on the server that will serve the certificate means it never has to travel.
- Restrict file permissions. Only the web server process or an administrator account should be able to read the key file. On Linux this commonly means a file readable only by the owner or a dedicated group.
- Keep it out of web-accessible folders. The key must never sit in the public document root, in a repository, in a shared drive or in an email attachment.
- Back up carefully. An encrypted backup in a secure place is better than having no copy, but every extra copy increases exposure. Record who holds one and why.
- Consider a passphrase or hardware protection. A passphrase on the key file helps if the file is stolen, though it complicates automatic server restarts. Larger organisations use hardware security modules or managed key services.
- Use separate keys for separate certificates and environments. Do not copy the same production key to a test server.
- Remove old copies. After a server is retired, securely delete the keys that lived on it.
What to do if the key is lost or leaked
The two situations differ.
Lost without being leaked. If you cannot find the private key, the certificate cannot be installed on a new server, because you cannot prove ownership of the public key. The solution is simple: generate a new key pair, create a new certificate signing request, and ask the issuer to reissue the certificate. Most providers support reissuing within the validity period; check the terms on the product page for your certificate.
Leaked or possibly leaked. Treat this as an incident:
- Generate a new key pair on a clean machine.
- Request a replacement certificate using the new key, and install it.
- Ask the issuing authority to revoke the old certificate.
- Find out how the key was exposed and fix that, for example a public repository, a misconfigured backup or a compromised server. Replacing keys without fixing the cause only repeats the problem.
- Check access logs for signs of misuse, and if the server itself was compromised, rebuild it before trusting the new key there.
Keep in mind that revocation checking depends on browsers and clients, and it is not instant everywhere. This is another reason to prevent exposure rather than rely only on cleanup.
A practical example
A small agency manages several client sites. A freelancer builds a site and, to help with a migration, zips the whole server folder including the private key and sends it to a colleague through a chat tool. Months later the freelancer's laptop is lost. Nobody knows whether the archive still exists somewhere.
The sensible response is not panic but a routine: generate a new key on the production server, order a reissued certificate with a new request, install it, revoke the old certificate, and document where keys must and must not be stored. The agency also adds a rule that private keys are never sent through chat or email, and migration scripts are updated to create keys on the destination server. This is also a good moment to check that the rest of the stack is sound, because, as explained in why HTTPS sites can still be attacked, a certificate alone does not protect a site.
Limits and what to watch for
- A strong key does not fix a weak server. If an attacker gets administrator access, they can read the key from memory or disk, whatever its size.
- Keys do not last forever. Certificates have limited validity, and you should plan renewals and key rotation in advance.
- Do not paste private keys into online tools. Some websites offer to "check" or "convert" a key. Use local command line tools on your own machine instead.
- Match the key and the certificate. An installation fails when the certificate was issued for a different key. Check that the public key in the certificate and in your private key match before installing.
- Do not confuse the keys with passwords. A private key is a long random value with no practical way to guess or reset it.
- Public key sharing is normal. Do not worry that the certificate contains a public key that everyone can see; that is how the system is designed.
Summary
An SSL certificate depends on a key pair. The public key is placed in the certificate and shared with every visitor, and it lets browsers verify signatures and set up encryption. The private key stays secret on your server and proves that the site really is the owner of the certificate. Generate it where it is used, restrict access to it, avoid copying it around, and have a replacement plan ready for loss or leakage. If you are preparing to order a certificate for your site, the SSL page is a good place to compare certificate types before you create your key and request.
Frequently asked questions
Is the public key secret?
No. The public key is placed inside the certificate and is sent to every visitor. It is designed to be shared. Only the matching private key must be kept secret.
Does the certificate authority ever see my private key?
No, and it should never ask for it. When you order a certificate you send a certificate signing request that contains the public key and your details. The private key stays on your own server or device.
What happens if my private key is leaked or lost?
If it leaks, treat the certificate as compromised: generate a new key pair, get a new certificate issued and ask the issuer to revoke the old one. If you lose it without a leak, you cannot use the old certificate on a new server and need to reissue it with a new key.
Can I reuse the same private key when I renew?
It is possible, but generating a fresh key pair for each new certificate is the better habit. A new key limits the damage if an old copy was exposed somewhere without you knowing.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Need an SSL certificate?
Pick the certificate type that fits your site and see the price before you check out.
SSL from $14.99
See SSL certificatesKeep reading

SSL Guides
TLS 1.2 vs TLS 1.3: What Actually Changes for Your Website
TLS 1.3 is faster to set up and removes old, risky options, while TLS 1.2 is still common. Learn the real differences and how to check your own site.
9 min read

SSL Guides
What Is a CSR and When Do You Need to Create One Before Ordering SSL?
A Certificate Signing Request carries your public key and site details to the certificate authority. See when you need it, how to create it and common mistakes.
9 min read

SSL Guides
Why a Website With HTTPS Can Still Be Attacked
HTTPS encrypts traffic between a visitor and a server, but attackers have many other routes. Learn what the padlock covers, what it misses and how to close the gaps.
10 min read