Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 84Security · TLS

How to create a self-signed certificate

For a lab, an internal admin tool or a test server you need HTTPS, but the name is not public — so Let's Encrypt can not help. A self-signed certificate (or one from your own small CA) encrypts the traffic just as well; browsers only warn because they do not know the issuer. This how-to makes a correct certificate (with SAN — browsers ignore the CN today), makes your own CA for many internal names, and lets your servers trust it.

  • 5 Lessen
  • 6 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

84.1

The quick answer

openssl req -x509 -newkey rsa:2048 -nodes -days 365 -keyout lab.key -out lab.crt -subj "/CN=lab.example.com" -addext "subjectAltName=DNS:lab.example.com,IP:10.0.1.11"
chmod 600 lab.key
openssl x509 -in lab.crt -noout -subject -ext subjectAltName -enddate

-nodes = the key has no passphrase (the web server can start alone) — protect it with 600 rights.

84.2

Step by step

  1. Always add a SAN — every name and IP you will use. Without it, browsers and modern clients reject the certificate even if the CN is right.
  2. Smaller and faster: an EC key (all modern clients support it):
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes -days 365 -keyout lab.key -out lab.crt -subj "/CN=lab.example.com" -addext "subjectAltName=DNS:lab.example.com"
  1. Many internal servers? Make your own small CA once, then sign server certificates with it — you trust one CA instead of every certificate:
openssl req -x509 -newkey rsa:4096 -nodes -days 1825 -keyout ca.key -out ca.crt -subj "/CN=ACME Internal CA"
openssl req -newkey rsa:2048 -nodes -keyout grafana.key -out grafana.csr -subj "/CN=grafana.lab.example.com"
printf 'subjectAltName=DNS:grafana.lab.example.com\nextendedKeyUsage=serverAuth\n' > san.ext
openssl x509 -req -in grafana.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 398 -out grafana.crt -extfile san.ext

Keep ca.key offline and safe — whoever has it can make certificates your servers trust.

  1. Use it in Nginx:
/etc/nginx/conf.d/lab.conf (part)
    listen 443 ssl;
    server_name lab.example.com;
    ssl_certificate     /etc/pki/tls/certs/lab.crt;
    ssl_certificate_key /etc/pki/tls/private/lab.key;
  1. Let your servers trust your CA (curl, apps, Docker):
cp ca.crt /etc/pki/ca-trust/source/anchors/acme-internal-ca.crt && update-ca-trust
cp ca.crt /usr/local/share/ca-certificates/acme-internal-ca.crt && update-ca-certificates

First line RHEL, second Ubuntu. For laptops, import ca.crt in the OS or browser trust store (or let IT push it).

  1. Know the limits: never use self-signed certificates for public sites (users learn to click away warnings) — use Let's Encrypt. For internal at scale: an internal CA service (Vault PKI, step-ca, cert-manager in Kubernetes).

84.3

Check that it worked

openssl x509 -in lab.crt -noout -ext subjectAltName
X509v3 Subject Alternative Name:
    DNS:lab.example.com, IP Address:10.0.1.11
curl --cacert ca.crt https://grafana.lab.example.com -o /dev/null -w '%{http_code}\n'
200

With the CA trusted, curl works without -k.

84.4

Common problems

ProblemCauseFix
NET::ERR_CERT_COMMON_NAME_INVALIDNo SAN, or the name is not in it.Recreate with -addext subjectAltName=….
NET::ERR_CERT_AUTHORITY_INVALIDThe issuer is not trusted.Expected for self-signed; trust your CA on the clients.
unknown option -addextVery old OpenSSL (< 1.1.1).Update OpenSSL, or use a config file with [v3_req].
Nginx: key values mismatchKey and certificate do not belong together.Compare openssl x509 -noout -pubkey with openssl pkey -pubout.
Browser says the validity is too longBrowsers limit server certs to ~398 days.-days 398 or less for server certificates.
Apps still fail after trusting the CAThe app has its own trust store (Java, Node, Python certifi).Add the CA there too (keytool, NODE_EXTRA_CA_CERTS, REQUESTS_CA_BUNDLE).

84.5

Go further

1Why do browsers reject a certificate that has the right CN but no SAN?

Modern clients only check the Subject Alternative Name list; the CN is ignored.

2Why make a small internal CA instead of many self-signed certificates?

You trust one CA on the clients, and every certificate it signs is trusted.

Alle commando's in dit hoofdstuk