I cloned a VM and the ssl certificate has the old hostname. I need to generate a new ssl certificate.
My question is what method was used by the server to create the initial certificate? Was this done as part of the post-install for an RPM? I'll use openssl if there's not a generation script that can be run. Thanks!
If you're concerned about preserving the current
localhost.crt
, move it from the directory then enter:in
/etc/pki/tls/certs
To answer the OP's question (as opposed to providing methods to generate localhost.crt): it depends on the Linux distribution and version. There are many distributions that use RPM, but I will mention two of the most widely used.
On CentOS 7/RHEL 7, it is done in the postinstall scriptlet of the
mod_ssl
package. Run the following command to see the full scriptlet:The part that actually creates the certificate is this:
On Fedora 29, things are a bit more complicated:
/usr/lib/systemd/system/httpd.service
) has a soft dependency on httpd-init.service./usr/lib/systemd/system/httpd-init.service
) is part of themod_ssl
package./usr/libexec/httpd-ssl-gencerts
, which generates the certificate usingsscg
.The relevant part of the
/usr/libexec/httpd-ssl-gencerts
is this:The
sscg
tool is a small stand-alone program (not a script). Quoting from the Fedora package description:You can quickly generate a new self-signed certificate and private key using the following command and just follow the prompts.
One thing I've found enormously useful when I don't care about the attributes of a certificate and just want the hostname to match is that you can pipe attributes into the openssl, just change test.example.tld in the command below to match whatever hostname you want to use. It'll leave all of the attributes blank and you'll end up with server.crt and server.key in your current directory: