OpenSSL is a free and open-source SSL solution that anyone can use for personal and commercial purpose. Though it is free, it can expire and you may need to renew it. This post will you how to renew self- signed certificate with OpenSSL tool in Linux server.
What do I need to know to renew my OpenSSL cert?
You must know the location of your current certificate that has expired and the private key. Since most of the Linux server admin like to put the cert files in the /etc/apache2/ssl directory, you can have a look at there for your existing cert file and the private key.
If you do not know your private key, do not worry because you can create a new one using the following command:
openssl genrsa -out /etc/apache2/ssl/mynew.key 2048
To renew the secure socket layer (SSL) cert, you need to follow two steps: create a CSR (certificate signing request) and generate the certificate with your private key. Remember that you must need a private key before creating your CSR.
Scenario: for example, you have a certificate called apache.crt which has been expired and you want to renew it for the next 365 days.
The complete procedures you need to follow:
- Create a certificate signing request with the following command:
openssl req -new -key /etc/apache2/ssl/mykey.key -out /etc/apache2/ssl/new.csr
- Check your certificate signing request information using the following commnd:
openssl req -in /etc/apache2/ssl/new.csr -noout –text
Before creating the new cert just rename the apache.crt file located in /etc/apache2/ssl so that you do not have to change anything the apache configuration file.
openssl x509 -req -days 365 -in /etc/apache2/ssl/new.csr -signkey /etc/apache2/ssl/mykey.key -out /etc/apache2/ssl/apache.crt
Note: in the above command 365 is the number of days after which your new certificate will expire. The name of key file is mykey.key and the name of certificate file is apache.crt. You need to change the name of bot the key and the CRT file name to match your existing certificate and the key file.
Next, restart apache2 server with the following command:
service apache2 restart
Finally, test the new expiry data of your certificate
openssl x509 -in /etc/apache2/ssl/apache.crt -noout -enddate