OpenSSL is a command-line tool that generates a self-signed certificate using cryptographic keys, typically for testing, internal services, or development environments where a trusted certificate authority is unnecessary.
Self-signed certificates are digitally signed by their own private key rather than a third-party CA. They verify identity through the certificate's own signature, not external validation. This makes them unsuitable for public websites but ideal for local servers, API testing, or internal applications.
The process uses OpenSSL's req command to generate a key pair and sign a certificate request. The resulting files include a .crt (certificate) and .key (private key), both in PEM format-Base64-encoded ASCII text that can be viewed in a plain text editor.
When you run the OpenSSL command to create a self-signed certificate, the tool performs several steps:
Because the certificate is signed by its own private key, no external trust chain exists. Browsers and clients will flag such certificates as untrusted unless manually accepted.
For example, if you're setting up a local web server at https://localhost, a self-signed certificate prevents connection errors during development while avoiding the cost and complexity of a CA-issued certificate.
Two core files are generated:
| File | Extension | Purpose | Format |
|---|---|---|---|
| Private Key | .key |
Used to decrypt data and sign messages | PEM (Base64) |
| Certificate | .crt |
Published to clients to verify server identity | PEM (Base64) |
Both files are human-readable. A PEM certificate begins with -----BEGIN CERTIFICATE----- and ends with -----END CERTIFICATE-----. The private key follows the same pattern with -----BEGIN PRIVATE KEY-----.
These files are not encrypted by default. Anyone with access to the .key file can impersonate the server. Always restrict file permissions using chmod 600 filename.key to prevent unauthorized access.
Developers use self-signed certificates to test HTTPS functionality locally. For example, when running a Node.js app with Express and requiring TLS, a self-signed cert avoids browser warnings during debugging.
System administrators deploy them in internal networks where centralized PKI is not available. A company might issue a self-signed certificate for an internal dashboard at https://intranet.company.local, then distribute the .crt file to employee devices to bypass trust warnings.
Another use is securing communication between microservices in a Kubernetes cluster. Tools like Istio or Linkerd support self-signed certificates for mutual TLS (mTLS) between pods, reducing reliance on external CAs.
Self-signed certificates are often mistaken for certificates issued by Certificate Authorities (CAs). A CA-issued certificate includes a chain of trust verified by browsers and operating systems. A self-signed certificate lacks this chain.
Also, people assume that self-signed certificates are inherently insecure. While they don't provide third-party validation, they still encrypt traffic and authenticate identity within a controlled environment. The risk lies in misuse-not in the technical design.
A common error is confusing the openssl req command with openssl x509. The former creates a CSR; the latter signs one. To generate a self-signed certificate, you must use -x509 flag with openssl req to skip the CSR step and sign directly.
Here's a complete, working example to generate a self-signed certificate for test.example.com:
openssl req -x509 -newkey rsa:2048 -keyout test.key -out test.crt -days 365 -nodes -subj "/C=US/ST=California/L=San Francisco/O=Test Org/CN=test.example.com"
This command:
-x509 to generate a self-signed certificate.test.key and certificate to test.crt.-nodes.-subj.After execution, two files appear: test.key and test.crt. You can view them with cat test.crt or cat test.key.
To validate the certificate, use:
openssl x509 -in test.crt -text -noout
This displays the certificate's issuer, subject, validity period, and public key algorithm. Confirm that Issuer and Subject match, which confirms it's self-signed.
I once set up a local API server using Node.js and Express. After configuring HTTPS with a self-signed certificate, I encountered a "NET::ERR_CERT_AUTHORITY_INVALID" error in Chrome. The fix was straightforward: export the test.crt file and install it in the system's trusted root store. On macOS, I opened Keychain Access, imported the certificate, and marked it as trusted. After that, the browser accepted the connection without warning.
Many guides claim that self-signed certificates are "not secure." That's misleading. Security depends on proper key management, not the signing method. A well-protected 2048-bit private key is cryptographically sound, even if not issued by a CA.
Another myth: self-signed certificates cannot be revoked. This is false. You can revoke them by maintaining a Certificate Revocation List (CRL) or using Online Certificate Status Protocol (OCSP), though these require manual setup and are rarely implemented in self-signed scenarios.
Finally, some users think the -nodes flag disables encryption entirely. It doesn't. It only skips password protection on the private key. The key is still encrypted using RSA. Removing the password only reduces usability-not security.
Always remember: self-signed certificates are tools, not risks. Use them wisely in isolated environments. For production systems, obtain a certificate from a trusted CA like Let's Encrypt.