هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
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.
Step by step
- 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.
- 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"- 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.extKeep ca.key offline and safe — whoever has it can make certificates your servers trust.
- Use it in Nginx:
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;- 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-certificatesFirst line RHEL, second Ubuntu. For laptops, import ca.crt in the OS or browser trust store (or let IT push it).
- 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).
Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
NET::ERR_CERT_COMMON_NAME_INVALID | No SAN, or the name is not in it. | Recreate with -addext subjectAltName=…. |
NET::ERR_CERT_AUTHORITY_INVALID | The issuer is not trusted. | Expected for self-signed; trust your CA on the clients. |
unknown option -addext | Very old OpenSSL (< 1.1.1). | Update OpenSSL, or use a config file with [v3_req]. |
Nginx: key values mismatch | Key and certificate do not belong together. | Compare openssl x509 -noout -pubkey with openssl pkey -pubout. |
| Browser says the validity is too long | Browsers limit server certs to ~398 days. | -days 398 or less for server certificates. |
| Apps still fail after trusting the CA | The app has its own trust store (Java, Node, Python certifi). | Add the CA there too (keytool, NODE_EXTRA_CA_CERTS, REQUESTS_CA_BUNDLE). |
Go further
- Command pages: openssl, curl, nginx.
- Next how-tos: Get a free TLS certificate with Let's Encrypt, Check when a TLS certificate expires, Check the TLS settings of a website.
- Full guides: cert-manager, Vault. Learn it: CKA — TLS for Ingress.
- Practise: Lab: applied cryptography with OpenSSL.
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.