Ssl – Generating a key file and CSR on Apache with OpenSSL

Apache2opensslsslssl-certificate

I need to get a new SSL cert sorted and have been watching this guide. When he creates his key and CSR he uses the below two commands.

sudo openssl genrsa -out /opt/bitnami/apache2/conf/server.key 2048

sudo openssl req -new -key /opt/bitnami/apache2/conf/server.key -out /opt/bitnami/apache2/conf/cert.csr 

These two files already exist on the server. I am worried that if I remove them to perform the above steps which creates them again it will cause problems with the current cert? Can I just run the commands and output different files? Say something like this? And if I did would I need to change any configuration to reflect those new file names?

sudo openssl genrsa -out /opt/bitnami/apache2/conf/server-new.key 2048 

sudo openssl req -new -key /opt/bitnami/apache2/conf/server-new.key -out /opt/bitnami/apache2/conf/cert-new.csr 

Best Answer

You can definitely use different output file paths with those openssl commands and you probably should until you get your actual SSL cert. Looking at those paths, /opt/bitnami/apache2/conf/server.key looks suspiciously like the one in use by Apache. If you were to replace that key with a new key, Apache would probably stop being able to host HTTPS requests the second it restarted.

Remember that a CSR is not your certificate, it's a request for someone else to sign your public key. You can put these files anywhere you like as long as you keep track of them. Create your new key file with that first command in some location like your home directory. For example, if my ssh username is sneakyimp, I might do this:

# make a new directory for the new key and CSR
/home/sneakyimp/new-cert
# generate my private key
sudo openssl genrsa -out /home/sneakyimp/new-cert/server.key 2048
# generate the CSR:
sudo openssl req -new -key /home/sneakyimp/new-cert/server.key -out /home/sneakyimp/new-cert/cert.csr

Then, after I received the certificate from digicert or symantic or whatever, I would install these in the appropriate locations specified in my apache configuration file. Apache configuration details vary by OS and machine.