الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

openssl

The Swiss army knife for TLS: make keys and certificate requests, read and check certificates, test TLS servers, hash and encrypt.

المستوى
خدمة DevSecOps
المجموعة
الأسرار والهوية والتشفير
يحتاج root
لا
الحزمة
openssl

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

openssl has many subcommands. In daily DevSecOps work you use it to create keys and CSRs for certificates, read certificates (expiry, names, issuer), test HTTPS and other TLS servers (s_client), convert formats (PEM, DER, PKCS#12), make random passwords and check file hashes.

RHEL uses system-wide crypto policies (update-crypto-policies); OpenSSL follows them (for example DEFAULT disables TLS 1.0/1.1).

طريقة الكتابة

openssl SUBCOMMAND [OPTIONS]

الأجزاء الرئيسية

Subcommands

genpkey / req / x509
Keys / requests / certificates.
s_client
Connect to a TLS server and show the handshake.
x509 -in FILE -noout -text
Read a certificate.
verify
Check a certificate chain.
pkcs12
Make or read .pfx/.p12 bundles.
rand
Random bytes (passwords, keys).
dgst
Hashes and signatures (sha256).
enc
Symmetric encryption of files.
pkey
Read and convert private keys.
ciphers
List cipher suites.
version -a
Version and settings.

الخيارات 10

الأكثر استخدامًا

Common options

-in FILE / -out FILE
Input / output file.
-noout
Do not print the encoded object.
-text
Print in readable text.
-subj "/CN=…"
Subject without questions.
-addext "subjectAltName=DNS:…"
Add SAN names (needed by browsers).
-days N
Validity of a self-signed certificate.
-servername NAME
SNI host name (s_client).
-connect HOST:PORT
Server to test (s_client).
-showcerts
Show the full chain (s_client).
-starttls smtp|imap|ftp
Upgrade a plain connection (s_client).

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Make a key and a CSR with SAN names

    openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out shop.key
    openssl req -new -key shop.key -out shop.csr -subj "/CN=shop.example.com" -addext "subjectAltName=DNS:shop.example.com,DNS:www.shop.example.com"
    openssl req -in shop.csr -noout -text | grep -A1 "Subject Alternative"
  2. 2A self-signed certificate for a lab

    openssl req -x509 -newkey rsa:3072 -nodes -keyout lab.key -out lab.crt -days 365 -subj "/CN=lab.local" -addext "subjectAltName=DNS:lab.local,IP:192.168.122.10"
  3. 3Read a certificate

    openssl x509 -in shop.crt -noout -subject -issuer -dates
    openssl x509 -in shop.crt -noout -ext subjectAltName
  4. 4Check expiry of a live site

    echo | openssl s_client -connect s0sta.com:443 -servername s0sta.com 2>/dev/null | openssl x509 -noout -enddate
    notAfter=Jan 20 09:12:44 2027 GMT
  5. 5Will it expire within 30 days? (for monitoring)

    openssl x509 -in shop.crt -noout -checkend 2592000 && echo "OK" || echo "Expires soon"
  6. 6Test which TLS versions a server accepts

    openssl s_client -connect shop.example.com:443 -tls1_1 </dev/null
    openssl s_client -connect shop.example.com:443 -tls1_3 </dev/null 2>/dev/null | grep -E "Protocol|Cipher"
  7. 7Test mail server TLS

    openssl s_client -connect mail.example.com:587 -starttls smtp </dev/null | head -20
  8. 8Check that a key and a certificate belong together

    openssl x509 -in shop.crt -noout -pubkey | openssl sha256
    openssl pkey -in shop.key -pubout | openssl sha256
  9. 9Verify a chain

    openssl verify -CAfile chain.pem shop.crt
  10. 10Make a .pfx for Windows / Azure

    openssl pkcs12 -export -inkey shop.key -in shop.crt -certfile chain.pem -out shop.pfx
  11. 11Random password and file hash

    openssl rand -base64 24
    openssl dgst -sha256 release.tar.gz

انتبه

  • Keep private keys chmod 600; never paste them into tickets or chats.
  • -nodes means the key is not encrypted — fine for servers, protect the file.
  • Browsers ignore the CN; always add subjectAltName.

الملفات

/etc/pki/tls/
Certificates and keys on RHEL (certs/, private/).
/etc/pki/ca-trust/source/anchors/
Add your own CA here, then update-ca-trust.
/etc/crypto-policies/
System crypto policy.

نصائح للحفظ

  • update-crypto-policies --show shows the policy; FUTURE is stricter, DEFAULT:SHA1 is for old systems only.

رموز الخروج

0Success.
1Error (verify failed, bad input …).