export ssl certificate from a windows environment to linux
have you ever generated your ssl csr (certificate signing request) request on a windows box and needed to install it on linux afterwards?
first, you have to get the certificate and private key out of windows,preferably in a pfx (pkcs #12) format.
- click start, run, then type “mmc” and hit enter.
- in the leftmost menu, choose “add/remove snap in”.
- click “add”, then click “certificates”, then ok.
- when the wizard starts, choose “computer account”, “local computer” and finish out the wizard.
- once you’re finished, get back to the mmc and expand the “certificates” node, then the “personal” node.
- click on the “certificates” node under “personal” and find your certificate in the right pane.
- right click on the certificate and choose “all tasks”, then “export”.
- when the wizard starts, choose “yes” for exporting the private key, then select only “strong private key protection” from the pfx section. you will also need to set a password and specify a location for the pfx file.
- once the pfx file has been saved, close out the mmc (don’t save the snap-in if it asks).
- get the pfx over to the linux server somehow.
once the pfx makes it over to the linux server, you have to decrypt the pfx into a plaintext pem file (pfx’s are binary files, and can’t be viewed in a text editor):
openssl pkcs12 -in certificate.pfx -out temp.pem
you will be asked for the password for the pfx (which is the one you set in the windows wizard). once you enter that, you will be asked for a new password. this new password is used to encrypt the private key. you cannot proceed until you enter a password that is 4 characters or longer. remember this password!
when this step is complete, you should have a pem file that you can read in a text editor. open the file in a text editor and copy the private key and certificate to different files (private.key certificate.crt respectively). remember to keep the dashed lines intact when you copy the certificates – this is important. there is some additional text above the key, and also between the key and certificate – this text should be ignored and should not be included in the certificate and key files.
now that you have the key and certificate separated, you need to decrypt the private key (or face the wrath of webserver software every time you start it). you can decrypt the private key like this:
openssl rsa -in private.key -out private.key
provide the same file name twice and it will decrypt the key onto itself, keeping everything in one file. openssl will ask for a password to decrypt the key, and this is the password you set when you decrypted the pfx. if you forgot the password, you will need to start over from when you brought it over from the windows machine.
after this process, you should have four files, a pfx, pem, key, and crt. store away the pfx and pem, and you will use the key and certificate files to install into apache or whatever software you’re configuring to use ssl.
sslengine on sslcertificatefile /path/to/your/certificate.crt sslcertificatekeyfile /path/to/your/private.key
ssl on; ssl_certificate_key /path/to/private.key; ssl_certificate /path/to/certificate.crt;