First lets install OpenSSL on your Linux machine.
For Fedora and other Red Hat distributions.
For Debian, Ubuntu etc which use apt package manager
For Arch-based Linux distributions
Now to generate certificate along private key in single command we can do it like this.
during this process you will be asked about information regarding your certificate like Country Name, State or Province Name, City name, company name, fully qualified name of the server mean domain name for which you are generating certificate.
You can now use the my_private_key.pem
(private key) and my_certificate.pem
(self-signed certificate) in your web server configuration to enable SSL/TLS.
Also if you want to extract Public Key from the certificates you can do it too
Please note that self-signed certificates are not trusted by browsers and should only be used for testing or development purposes. For production use, consider obtaining a certificate from a trusted certificate authority (CA).