How to Get .Pem File From .Key and .Crt Files?

SSL
Better Stack Team
Updated on October 7, 2024

To create a .pem file from a .key (private key) and a .crt (certificate) file, you need to combine them into a single .pem file. Here's how you can do it:

Step 1: Understand the Files

  • .key file: This is your private key, usually generated when you create a Certificate Signing Request (CSR).
  • .crt file: This is your SSL certificate, which might be issued by a Certificate Authority (CA) or self-signed.

Step 2: Combine the .key and .crt Files into a .pem File

You can simply concatenate the .key and .crt files to create a .pem file using the cat command in the terminal:

 
cat your_certificate.crt your_private.key > combined_certificate.pem

Example

If your files are named server.crt and server.key, you would use:

 
cat server.crt server.key > server.pem

Explanation

  • cat server.crt server.key: Concatenates the contents of server.crt and server.key.
  • > server.pem: Redirects the concatenated output into a new file called server.pem.

Step 3: Verify the .pem File (Optional)

You can verify the contents of the .pem file to ensure that it includes both the certificate and the private key:

 
openssl x509 -in server.pem -text -noout

This command will display the contents of the certificate part of the .pem file.

Summary

The resulting .pem file will contain both your private key and certificate, and it can be used in applications that require a .pem format, such as certain web servers or other SSL/TLS implementations.

Got an article suggestion? Let us know
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github