PEM vs. PFX: How to Move a TLS Certificate Between Servers
Use OpenSSL to distinguish PEM certificates from PFX bundles, keep the key private, and verify the certificate chain after moving a TLS endpoint.
- tls
- openssl
- certificates
- guide
PEM describes a text encoding. A file in that encoding can hold a public certificate, a private key or several certificates, depending on what is inside. PFX, also called PKCS #12 and often saved as .p12, is a container. It can carry a private key and certificate chain together. Check which files the destination needs before exporting a key.
Identify what the destination imports
If the new server or managed host can issue its own certificate, you may be able to avoid moving the original private key. If you must reuse the certificate, check whether the importer wants a PFX bundle or separate leaf, chain and key files. A leaf certificate is the one for your hostname. The chain generally includes the intermediate certificates that connect it to the trust anchor clients already have.
| File label or format | What can be inside |
|---|---|
PEM with BEGIN CERTIFICATE | A public certificate. There can be more than one block. |
PEM with BEGIN PRIVATE KEY or BEGIN ENCRYPTED PRIVATE KEY | A private key. Keep the entire file in your approved key store. |
.pfx or .p12 | A PKCS #12 container. Treat the whole file as sensitive until you know what it contains. |
The file extension is a clue. The destination's import documentation and a content check are stronger evidence.
Check a bundle without printing key material
On an approved machine, use openssl pkcs12 -in site.pfx -info -noout to inspect the container structure. Let OpenSSL prompt for the password. To export public leaf certificate material without the private key, use openssl pkcs12 -in site.pfx -clcerts -nokeys -out leaf.pem. The OpenSSL manual explains how those options select content.
When the destination requires a PFX file, a typical export from separate files is openssl pkcs12 -export -in leaf.pem -inkey site-key.pem -certfile intermediates.pem -out site.pfx. Use a protected working directory, a password delivered through a separate approved channel, and locally controlled filenames. Ensure the extra file contains the intermediates your destination expects. An archive password protects the exported copy; the destination still needs permission controls and a private-key lifecycle.
Verify what the live server sends
Open the imported certificate on the destination and check its hostname coverage and expiration. After switching traffic, use a browser and an independent TLS certificate check against the actual hostname. A successful import can coexist with a wrong virtual host or a missing intermediate. Verify the public endpoint and remove the temporary export under your key-handling policy after the move is confirmed.
