Security Basics — SSH, TLS and Certificates›10 · Self-signed certificates and your own CA

Lesson 10 of 16 · HTTPS and certificates

Self-signed certificates and your own CA

Hands-on with openssl: create a self-signed certificate in one command, see why clients reject it, then build a small private CA, issue a proper server certificate with SANs and key usage, serve it, and make clients trust it the right way instead of switching verification off. When each approach is acceptable, and the tools that automate it.

Practitioner
Key wordsself-signed certificateprivate CAopenssl req -x509openssl x509 -reqCSRSANtrust a CAcurl --cacertupdate-ca-certificatesinsecure skip verifymkcertstep-cacert-manager

Lab only

Run these in an empty directory on a test machine. The CA key made here is for learning; a real private CA needs a protected key (lesson notes below).

Part 1: a self-signed certificate

Self-signed means the certificate is signed by its own key: subject and issuer are the same.

$ openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
    -keyout self.key -out self.crt -days 30 -subj "/CN=app.lab.test" \
    -addext "subjectAltName=DNS:app.lab.test,IP:127.0.0.1"
$ openssl x509 -in self.crt -noout -subject -issuer -dates
subject=CN = app.lab.test
issuer=CN = app.lab.test
notBefore=Nov  7 18:37:23 2026 GMT
notAfter=Dec  7 18:37:23 2026 GMT
$ openssl verify self.crt
error 18 at 0 depth lookup: self-signed certificate
error self.crt: verification failed

The encryption is just as strong as with any certificate. What is missing is proof of identity: anyone can run that command with any name. That is why browsers show a full-page warning and curl refuses.

A self-signed certificate is like a badge you printed yourself that says "Official Inspector". It might be true, but nobody can tell, because anyone with a printer can make one. A private CA is like your school printing badges for its own staff: people inside the school know the school's stamp and trust it.

Part 2: a small private CA

1. The CA: a key and a self-signed certificate marked CA:TRUE, allowed only to sign certificates.

$ openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
    -keyout ca.key -out ca.crt -days 3650 -subj "/CN=Lab Root CA" \
    -addext "basicConstraints=critical,CA:TRUE" \
    -addext "keyUsage=critical,keyCertSign,cRLSign"

2. The server's key and CSR (on the server, in real life):

$ openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
    -keyout web.key -out web.csr -subj "/CN=web.lab.test"

3. The CA signs it, adding the SANs and purposes from an extensions file:

$ cat > web.ext <<'EOF'
subjectAltName=DNS:web.lab.test,DNS:www.lab.test
basicConstraints=CA:FALSE
keyUsage=critical,digitalSignature
extendedKeyUsage=serverAuth
EOF
$ openssl x509 -req -in web.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
    -out web.crt -days 90 -extfile web.ext
Certificate request self-signature ok
subject=CN = web.lab.test
$ openssl verify -CAfile ca.crt web.crt
web.crt: OK

Part 3: serve it and test the client side

$ openssl s_server -accept 8443 -cert web.crt -key web.key -www &
$ curl --resolve web.lab.test:8443:127.0.0.1 https://web.lab.test:8443/
curl: (60) SSL certificate problem: unable to get local issuer certificate
$ curl --cacert ca.crt --resolve web.lab.test:8443:127.0.0.1 https://web.lab.test:8443/ -o /dev/null -w "%{http_code}\n"
200
$ curl --cacert ca.crt --resolve other.lab.test:8443:127.0.0.1 https://other.lab.test:8443/
curl: (60) SSL: no alternative certificate subject name matches target host name 'other.lab.test'
$ kill %1

Three results, three lessons: unknown CA is rejected; trusting the CA works; trusting the CA does not switch off the name check.

To trust the CA for every program on a Debian/Ubuntu machine:

$ sudo cp ca.crt /usr/local/share/ca-certificates/lab-root.crt
$ sudo update-ca-certificates

Do not "fix" it by switching verification off

curl -k, verify=False in Python, InsecureSkipVerify: true in Go, NODE_TLS_REJECT_UNAUTHORIZED=0: all of these turn off every check, so any attacker in the middle is accepted. They tend to escape from test code into production. Trust the right CA instead.

When to use which

Approach Fine for Not for
Self-signed A quick local test, one-off lab Anything other people or programs connect to regularly
Private CA Internal services, mTLS between services, devices, staging Public websites (visitors don't trust your CA)
Public CA (lesson 11) Anything on the internet Internal-only names

A real private CA needs more

  • Keep the root key offline; issue from an intermediate.
  • Use short lifetimes and automation instead of hand-signing: mkcert (developer laptops), step-ca or HashiCorp Vault PKI (internal CA services), cert-manager (Kubernetes).
  • Keep an inventory of what was issued and when it expires.

Recap

  • Self-signed = encrypted but identity unproven; clients reject it by default.
  • A private CA signs certificates your own clients trust once the CA certificate is in their trust store.
  • Put SANs, CA:FALSE, key usage and EKU on server certificates.
  • Never disable verification; trust the CA instead. Protect ca.key above everything.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.