自己署名SSL証明書の発行コマンド
以下の項目が揃っていれば、一発で発行できます。
openssl req -newkey rsa:4096 \
-x509 \
-sha256 \
-days 365 \
-nodes \
-out nginx_selfsigned.crt \
-keyout nginx_selfsigned.key \
-subj "C=JP/ST=Tokyo/L=Minato/O=42Tokyo/CN=localhost"
各フラグの意味
name |
description |
-newkey rsa:4096 |
Creates a new certificate request and 4096 bit RSA key. The default one is 2048 bits. |
-x509 |
Creates a X.509 Certificate. |
-sha256 |
Use 265-bit SHA (Secure Hash Algorithm). |
-days 365 |
The number of days to certify the certificate for. You can use any positive integer. |
-nodes |
Creates a key without a passphrase. |
-out example.crt |
Specifies the filename to write the newly created certificate to. You can specify any file name. |
-keyout example.key |
Specifies the filename to write the newly created private key to. You can specify any file name. |
-subj |
User Information |
-subjフラグの詳細
name |
description |
C= |
Country name. The two-letter ISO abbreviation. |
ST= |
State or Province name. |
L= |
Locality Name. The name of the city where you are located. |
O= |
The full name of your organization. |
OU= |
Organizational Unit. |
CN= |
The fully qualified domain name. |
※The fully qualified domain name.とは、完全修飾ドメイン名。ホスト名が省略されていないドメイン名のこと
おまけ SSL証明書関係の拡張子一覧
拡張子 |
示すもの |
description |
.der |
エンコーディング方式 |
鍵や証明書をASN.1というデータ構造で表し、それをシリアライズしたバイナリファイルです。 |
.pem |
エンコーディング方式 |
DERと同じASN.1のバイナリデータをBase64によってテキスト化されたファイルです。 |
.crt |
ファイルの中身 |
Certificate 証明書 |
.cer |
ファイルの中身 |
Certificateの略、つまり証明書です。マイクロソフトが使っている拡張子の取り決めで使われています。 |
.key |
ファイルの中身 |
公開鍵、あるいは秘密鍵であることを表しています。 |
参考
/docs/man1.0.2/man1/openssl-req.html
Creating a Self-Signed SSL Certificate | Linuxize