Generating a private key

Last Updated : Aug 31, 2016 |

About this task

Use this procedure to generate a private key if you want to use HTTPS (HTTP over TLS) to secure your Apache HTTP or Nginx web server, and you want to use a Certificate Authority (CA) to issue the SSL certificate.

Procedure

Run the following command: openssl req -newkey rsa:2048 -nodes -keyout my-private-key-file.key.

This command creates a 2048-bit private key. The -newkey rsa:2048 option specifies that the key should be 2048-bit, generated using the RSA algorithm. The -nodes option specifies that the private key should not be encrypted with a pass phrase.

Example

# openssl req -newkey rsa:2048 -nodes -keyout myPrivateKey.key
Generating a 2048 bit RSA private key
........+++
.........................+++
writing new private key to 'myPrivateKey.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:IN
State or Province Name (full name) []:Maharashtra
Locality Name (eg, city) [Default City]:Pune
Organization Name (eg, company) [Default Company Ltd]:Avaya
Organizational Unit Name (eg, section) []:Avaya
Common Name (eg, your name or your server's hostname) []:mihir-edp-3-2-113.platform.avaya.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:Avaya
-----BEGIN CERTIFICATE REQUEST-----
MIIC3TCCAcUCAQAwgYExCzAJBgNVBAYTAklOMRQwEgYDVQQIDAtNYWhhcmFzaHRy
YTENMAsGA1UEBwwEUHVuZTEOMAwGA1UECgwFQXZheWExDjAMBgNVBAsMBUF2YXlh
MS0wKwYDVQQDDCRtaWhpci1lZHAtMy0yLTExMy5wbGF0Zm9ybS5hdmF5YS5jb20w
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDYhtdcZybDwYG5lzMy8U2D
V+iAZWIQ8JWldhb45I8raEXxPOFg6CHaXNX9b6VShJuHVswRqSpgDB7RSWzQoF4B
oBnKHPY9JIo3v+iMyfKwEuyXQEYMsN3e3TYleMQzRiCGpsM7BvkVrTLrXb9MdEeK
s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