How to Generate an ECC (ECDSA) Certificate with OpenSSL on Ubuntu 26.04
Create an ECC (ECDSA) private key, a CSR and a self-signed certificate with Subject Alternative Names using OpenSSL 3 on Ubuntu 26.04 or 24.04.
This guide shows how to create an elliptic-curve (ECC, also called ECDSA) private key, a certificate signing request and a self-signed certificate with OpenSSL on Ubuntu 26.04 LTS. The commands are identical on Ubuntu 24.04 LTS and on any other distribution with OpenSSL 3. Ubuntu 14.04 is long out of standard support, and certificates made the way older tutorials describe, without a Subject Alternative Name, are rejected by current browsers.
Why use an ECC key
An ECC key gives the same level of security as a much longer RSA key. A 256-bit key on the P-256 curve is generally treated as comparable to a 3072-bit RSA key, so keys and certificates are smaller and TLS handshakes need less CPU time. All current browsers, operating systems and public certificate authorities support the two common curves:
| Curve | Other names | When to use it |
|---|---|---|
| P-256 | prime256v1, secp256r1 | The default choice for web servers |
| P-384 | secp384r1 | When a policy asks for a larger key |
Requirements
OpenSSL is part of a standard Ubuntu installation. Ubuntu 26.04 ships OpenSSL 3.5 and Ubuntu 24.04 ships OpenSSL 3.0. Check your version and, if the command is missing, install it:
openssl version
sudo apt update
sudo apt install -y openssl
The examples use the domain example.com. Work in a directory only you can read:
mkdir -m 700 ~/ecc-cert
cd ~/ecc-cert
Step 1: Generate the private key
Create a key on the P-256 curve:
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out private.key
For P-384, use ec_paramgen_curve:P-384 instead. Restrict the file permissions, because anyone who can read the key can impersonate your server:
chmod 600 private.key
Older tutorials use openssl ecparam -name prime256v1 -genkey -out private.key. That command still works and produces an equivalent key in the older "EC PRIVATE KEY" file format; genpkey is the current general-purpose command and writes the PKCS#8 format.
Inspect the key to confirm the curve:
openssl pkey -in private.key -noout -text
The output contains ASN1 OID: prime256v1 and NIST CURVE: P-256.
Step 2: Create a certificate signing request
If a certificate authority will issue the certificate, create a CSR. Browsers identify a site by the Subject Alternative Name (SAN) extension, not by the Common Name, so list every host name there:
openssl req -new -key private.key -sha256 \
-subj "/C=US/O=Example Company/CN=example.com" \
-addext "subjectAltName = DNS:example.com,DNS:www.example.com" \
-out certificate.csr
Leave out -subj if you prefer to be asked for each field. SHA-256 is the usual digest for a P-256 key; use -sha384 with a P-384 key. Check the request before you send it:
openssl req -in certificate.csr -noout -text -verify
Submit certificate.csr to your certificate authority. The private key never leaves your server.
Step 3: Create a self-signed certificate
For internal services, testing or a VPN, you can sign the certificate with its own key. This single command creates a certificate valid for 365 days directly from the key:
openssl req -x509 -new -key private.key -sha256 -days 365 \
-subj "/CN=example.com" \
-addext "subjectAltName = DNS:example.com,DNS:www.example.com" \
-out certificate.crt
Set -days explicitly: without it, openssl req -x509 issues a certificate that is valid for only 30 days. For a certificate that names an IP address, use IP:203.0.113.10 in the SAN list.
To generate the key and the certificate in one step instead of running step 1 first:
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -noenc \
-keyout private.key -out certificate.crt -sha256 -days 365 \
-subj "/CN=example.com" \
-addext "subjectAltName = DNS:example.com,DNS:www.example.com"
-noenc stores the key without a passphrase so that a service can load it unattended. It replaces the -nodes option, which is deprecated in OpenSSL 3.
Step 4: Verify the certificate
Show the subject, validity period and SAN entries:
openssl x509 -in certificate.crt -noout -subject -dates -ext subjectAltName
Confirm that the certificate belongs to the private key by comparing the public keys. Both commands must print the same hash:
openssl x509 -in certificate.crt -noout -pubkey | openssl sha256
openssl pkey -in private.key -pubout | openssl sha256
Step 5: Use the certificate
Move the files to the usual locations and keep the key readable by root only:
sudo install -m 644 certificate.crt /etc/ssl/certs/example.com.crt
sudo install -m 600 private.key /etc/ssl/private/example.com.key
Point your service at these two paths. In Nginx, for example:
ssl_certificate /etc/ssl/certs/example.com.crt;
ssl_certificate_key /etc/ssl/private/example.com.key;
Clients show a warning for a self-signed certificate until you import it into their trust store. For a public website, have the CSR from step 2 signed by a certificate authority instead.
Frequently asked questions
Which curves does my OpenSSL support?
Run openssl ecparam -list_curves. The list is long, but for TLS certificates stay with P-256 or P-384; other curves are not accepted by public certificate authorities or are poorly supported by clients.
Can I serve an ECC and an RSA certificate for the same site?
Yes. Nginx and Apache accept two certificate and key pairs for one site and pick the one the client supports. This only matters if you must support very old clients that cannot use ECDSA.
Should I protect the key with a passphrase?
A passphrase protects the key file at rest, but the web server then asks for it on every start, which prevents unattended restarts. Most servers use an unencrypted key with strict file permissions. To add a passphrase, append -aes-256-cbc to the genpkey command.
I lost the private key. Can I recover it from the certificate?
No. The certificate contains only the public key. Generate a new key and CSR and have the certificate reissued.