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 ofserver.crt
andserver.key
.> server.pem
: Redirects the concatenated output into a new file calledserver.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.
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 usBuild 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.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github