openssl req -new -x509 -days 3650 -keyout CARoot1024.key -out CARoot1024.crt
openssl rsa -in CARoot1024.key -out CARoot1024.key # 移除私鑰保護密碼
openssl req -newkey rsa:2048 -x509 -days 5480 -keyout CARoot2048.key -out CARoot2048.crt
openssl rsa -in CARoot2048.key -out CARoot2048.key
openssl genrsa -out app.key 2048
openssl req -new -key app.key -out app.csr
openssl ca -in app.csr -out app.crt -cert CARoot1024.crt -keyfile CARoot1024.key -days 1826 -policy policy_anything
openssl ca -extensions v3_ca -in app.csr -out app.crt -cert CARoot1024.crt -keyfile CARoot1024.key -days 1826 -policy policy_anything
關鍵差異:中繼 CA 需加 -extensions v3_ca 賦予簽發下級憑證權限;應用憑證(終端實體)不加此擴展。
req -new -x509 選項-days N:有效天數(僅配合 -x509 生效)。-keyout file:私鑰輸出檔名(若指定既有檔則覆寫)。-out file:憑證輸出檔名(建議勿省略,否則輸出到 stdout)。-key 時自動生成 RSA 私鑰,長度由 openssl.cnf 決定(預設 1024)。互動式提示輸入 PEM pass phrase。自動化腳本可用 -passout pass:密碼,但歷史指令可見,生產環境建議用 -passout file:密碼檔 或 -passout env:變數名。
| 欄位 | 縮寫 | 說明 | 建議 |
|---|---|---|---|
| Country Name | C | 國家代碼(2 字母) | 必填 |
| State/Province | ST | 州/省全名 | 選填 |
| Locality | L | 城市 | 選填 |
| Organization | O | 組織/公司名 | 建議填寫 |
| Org Unit | OU | 部門 | 選填 |
| Common Name | CN | 通用名(網域名或實體名) | 必填,應用憑證填網域(支援通配符) |
| - | 聯絡信箱 | 選填 |
使用預設值直接按 Enter;留空請輸入 . 再按 Enter。
openssl ca -config openssl.cnf 統一管理序號、資料庫、政策。