I've set up SSL on my webserver, now I need two files:
- a certificate
- a certificate Key
How do I create a self-signed certificate for testing purposes?
I've set up SSL on my webserver, now I need two files:
How do I create a self-signed certificate for testing purposes?
Ubuntu, even the 'minimal' flavour, comes with the
ssl-cert
package pre-installed, which means you don't need to do anything.The files you're looking for are already on your system:
Advanced:
If for some reason you need to create a fresh certificate, you can run
If you want to change the expiration date of you certificate, you can manipulate the make-ssl-cert script at
/usr/sbin/make-ssl-cert
. Around like 124 there's a line similar to this:Where you can change the expiration date by adding the
-days
argument:More options can be found in the manual page of
req
.As already mentioned, Ubuntu Server comes with the necessary tools. Depending on your server version you'll have to look up the specific documentation. I'll try to summarize the self-signed certificate generation process of the current LTS (12.04).
First you generate the keys for the Certificate Signing Request (CSR):
It's up to you to enter a passphrase or not. If you do, everytime you (re)start a service usign that certificate, you'll have to provide the passphrase. Otoh you can create an "insecure" key without a passphrase from the secure one:
And now you'll create the CSR from the key. With the CSR and the key a self-signed certificate can be generated:
The last step consists of installing the certificate and the key, in Debian/Ubuntu usually in
/etc/ssl
:And finally the applications using the certificate/key have to be configured accordingly.
The other answers are good, but if for some reason you dont have the listed tools, or dont want to use them, I found an open source tool that is very simple:
This will create key file
minica-key.pem
and cert fileminica.pem
. The tool for creating these is just a single file in the Go language, with no external dependencies:https://github.com/jsha/minica