証明書作成

鍵の作成

Bash
openssl genrsa -out

CSRの作成

Bash
openssl req -new -key -out

自己証明書発行

秘密鍵の作成、CSR作成、自己証明書作成は以下の手順で可能です。

Bash
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

CSRの発行まで一括で実施する

CSR作成までを一度に行うこともできます。

その場合はopenssl reqコマンドに-newkeyオプションを付けて鍵を作成し、-subjオプションで必要情報を記載します。

Bash
openssl req -new -newkey rsa:2048 -nodes \
  -keyout server.key -out server.csr \
  -subj "/C=JP/ST=Tokyo/L=Chiyoda-ku/O=Example Corp/OU=IT Dept/CN=www.example.com"

証明書の内容の確認

PEM形式の場合

Bash
openssl x509 -text -noout -in

DER形式の場合

Bash
openssl x509 -text -noout -inform der -in

証明書の有効期限を確認

Bash
openssl x509 -in -noout -dates

秘密鍵ファイル内容の確認

Bash
openssl rsa -text -noout -in

CSRファイル内容の確認

Bash
openssl req -text -noout -in