file-fusion.com → best free → financial aid meta → create a certificate using openssl
Posted on by Henry Wagner

create a certificate using openssl

Terminal window showing OpenSSL commands generating a certificate and private key

Creating a certificate using OpenSSL generates a digitally signed X.509 certificate tied to a private key, used to authenticate servers, clients, or software. The process involves generating a private key, creating a certificate signing request (CSR), and either signing the CSR with a Certificate Authority (CA) or self-signing it for internal use.

OpenSSL is a command-line toolkit implementing the TLS and SSL protocols. It handles cryptographic operations including key generation, certificate signing, and verification. When you create a certificate using OpenSSL, you're producing a file in PEM format containing public key data, identity information, and a signature verifying authenticity.

The most common output is a .crt or .pem file. These files are readable ASCII text, often beginning with -----BEGIN CERTIFICATE-----. They're used in web servers (like Apache or Nginx), APIs, and secure applications to establish encrypted connections and verify identities.

How It Works

Creating a certificate using OpenSSL follows a multi-stage workflow. First, generate a private key. Second, create a certificate signing request (CSR) that includes your public key and identifying details like domain name, organization, and location. Third, sign the CSR with a trusted CA or self-sign it for testing.

Self-signed certificates are valid for internal systems but trigger browser warnings because they aren't issued by a recognized authority. For production environments, submitting the CSR to a trusted CA (like Let's Encrypt, DigiCert, or Sectigo) results in a certificate accepted by browsers and operating systems.

Each step uses specific OpenSSL commands. The private key is generated with openssl genrsa. The CSR is created via openssl req. The certificate itself is produced with openssl x509, either by signing a CSR or self-signing.

Key Components and Types

A certificate contains several elements:

There are two primary types of certificates generated using OpenSSL:

Type Use Case Command Example
Self-signed Internal testing, development, or isolated networks openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
CA-signed Production websites, API services, client authentication openssl x509 -req -in csr.pem -CA ca.crt -CAkeyfile ca.key -CAcreateserial -out cert.crt -days 365

Self-signed certificates are faster to generate but require manual trust configuration. CA-signed certificates are interoperable across devices and browsers but require validation steps and may involve fees.

Where and Why It's Used

Creating a certificate using OpenSSL is standard practice in system administration, DevOps, and application development. It's essential for securing HTTPS traffic, enabling mutual TLS (mTLS) between microservices, and authenticating users or devices in enterprise environments.

For example, when setting up a new Nginx server, you'd generate a certificate using OpenSSL to enable HTTPS. Without it, browsers display "Your connection is not private." The certificate ensures data encryption and verifies the server's identity.

Another use case is securing internal APIs. A company might generate a certificate using OpenSSL for an internal service running on https://api.internal.company.local. Since this domain isn't publicly accessible, a self-signed certificate suffices and avoids external CA costs.

Common Confusions and Mistakes

Many assume that creating a certificate using OpenSSL automatically makes it trusted. This is false. A certificate is only trusted if the issuing CA is in the client's trust store. Self-signed certificates must be manually added to the system's root certificate store.

Another mistake is misconfiguring the Common Name (CN) field. If you generate a certificate for example.com but set the CN to www.example.com, browsers may reject it. The CN must match the domain exactly as accessed.

Some users run openssl req -new -keyout key.pem -out csr.pem and then forget to submit the CSR to a CA. The CSR is not a certificate-it's a request. You cannot use it directly in a server configuration.

A non-obvious error: using weak key sizes. Generating a 1024-bit RSA key is still supported by OpenSSL but is deprecated. Modern standards recommend 2048-bit keys or higher. Using rsa:2048 ensures compatibility with current security policies.

Real-World Example: Generate a Test Certificate

Suppose you need a test certificate for a local development server. Run this sequence:

openssl genrsa -out server.key 2048
openssl req -new -keyfile server.key -out server.csr

When prompted, enter:

Now self-sign the CSR:

openssl x509 -req -in server.csr -signkey server.key -out server.crt -days 365

This creates server.crt, a valid certificate for localhost. You can now configure your local web server to use server.key and server.crt.

I've used this exact flow in multiple Dockerized applications. The resulting certificate works in Chrome, Firefox, and curl-but only after importing the server.crt into the OS trust store. On macOS, double-clicking the file adds it to Keychain Access.

Distinctions and Corrections

Creating a certificate using OpenSSL is not the same as creating a certificate signing request (CSR). The CSR is a separate file used to request a signed certificate. You cannot serve a CSR as a certificate.

Also, OpenSSL does not manage certificate revocation. Once issued, a certificate remains valid until expiration unless manually revoked via a Certificate Revocation List (CRL) or Online Certificate Status Protocol (OCSP). This responsibility lies with the CA or internal PKI system.

Some tools claim to "generate certificates" but actually only produce CSRs. Always verify that the tool outputs a signed X.509 structure, not just a public key and metadata.

According to the National Institute of Standards and Technology (NIST), RSA keys under 2048 bits are no longer recommended for cryptographic use after 2021. NIST SP 800-57 Part 1 Revision 5 confirms that 2048-bit RSA keys provide adequate security through 2030.

Let's Encrypt, a widely used free CA, requires domain ownership verification before issuing certificates. Their automated process integrates with tools like Certbot, but manual creation using OpenSSL gives you full control over the certificate's attributes.

Next Steps

Always back up your private key. Losing it means you can't renew or revoke the certificate. Store it in a password-protected file or hardware security module (HSM) for high-security environments.

Understanding how to create a certificate using OpenSSL is foundational for anyone managing secure communications. It's not just about running commands-it's about knowing what each piece does and how it fits into the larger security picture.


Related Posts