Create self-signed certificate for Apache on one line

You need to create a self-signed certificate for httpd server by Apache Software Foundation I guess. There are thousands of tutorials out there. But I have the special one. A oneliner. Yeah! Do the following in an empty directory, /tmp for example.

openssl genrsa -out cert.key 1024 && echo -ne "\n\n\n\n\n$HOSTNAME\nroot@$HOSTNAME\n" | openssl req -new -key cert.key -x509 -out cert.crt -days 999

All done. Nasty, isn't it? You can check out your fresh certificate by issuing

openssl x509 -text -in cert.crt

As you can see the Subject and Issuer are the same. It's a self-signed certificate as I promised.

Two files were created. The cert.crt contains the certificate itself, the cert.key contains, guess what, the private key. Please note this is NOT recommended for production use. Only for quick & dirty certificates for development use. You have been warned!

Sit back and hit your That Was Easy (TM) button now.
17 February 2011 | english | httpd