When you need to generate a .pem file from .key (private key file) and .crt (certificate file) files, you can achieve this by merging the contents of these two files. PEM files typically contain SSL certificate and key information and are Base64 encoded. Below are the specific steps and examples:
Step 1: Prepare the Files
Ensure you have both .key and .crt files. Here, we assume the filenames are example.key and example.crt.
Step 2: Merge File Contents
You can use command-line tools to merge the contents of these files. The most common method is to use the cat command on Linux or Unix systems.
Execute the following command in the terminal:
bashcat example.key example.crt > example.pem
This command first copies the contents of example.key into example.pem, then appends the contents of example.crt to the same file.
Step 3: Verify the File
After merging, verify the newly created .pem file. Use the openssl tool to check its contents:
bashopenssl rsa -in example.pem -check
This command checks the integrity of the private key.
bashopenssl x509 -in example.pem -text -noout
This command displays the detailed information of the certificate.
Notes
- Ensure the correct order is maintained when merging: place the private key file (.key) first, followed by the certificate file (.crt).
- Work with these files in text mode, as they are text-based.
Example
If you have a private key file named myserver.key and a certificate file named myserver.crt, generate the PEM file as follows:
bashcat myserver.key myserver.crt > myserver.pem
This creates a myserver.pem file containing the necessary SSL certificate and private key information, suitable for server configuration requiring a .pem format certificate.