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.

FBFenwei BianAuthorNov 24, 2026
  • 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 formatWhat can be inside
PEM with BEGIN CERTIFICATEA public certificate. There can be more than one block.
PEM with BEGIN PRIVATE KEY or BEGIN ENCRYPTED PRIVATE KEYA private key. Keep the entire file in your approved key store.
.pfx or .p12A 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.

Sources and further reading

About the author(s)

Software Developer & Writer • Namefi
FBAuthor

Fenwei Bian is a software developer in her thirties who spends her working hours in pull requests and her weekends with her hands in soil or sawdust. Years of open source on GitHub taught her that names are interfaces: a good one is clear, honest about what it does, and kind to whoever has to use it next.

She gardens because it rewards patience and punishes wishful thinking, and she does woodwork because a joint either fits or it doesn't. Both habits show up in how she writes about naming — measure twice, check the source, and don't sand over a rough spot and hope no one notices.

For Namefi she writes about how domain markets actually move, the practical trade-offs of tokenizing and flipping names, and picking a domain you'll still be glad you own in twenty years.

Related guides

Discuss this post

View the discussion on Namefi Discuss