メニューSSL証明書 - メニュー
【SSL証明書】よくある質問(FAQ)

OpenSSLでCSR作成

ページ更新日:2023/05/03

opensslコマンドを使った秘密鍵とCSRの作成方法は次のとおりです。
秘密鍵にパスフレーズを設定しない方式と、秘密鍵にパスフレーズを設定する方式があります。

秘密鍵にパスフレーズを設定しない方式(一般的) と、
秘密鍵にパスフレーズを設定する方式(より安全) のどちらからでCSRを作成ください。

秘密鍵にパスフレーズを設定すると、Apache起動時にパスフレーズ入力が必要となり運用性が下がります。
そのため、秘密鍵にパスフレーズを設定されていない方のほうが圧倒的に多いと思われます。

OpenSSLでCSR作成(秘密鍵にパスフレーズを設定しない)

次の opensslコマンドを実行してCSRを作成します。

opensslコマンド実行

$ openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr

実行例

$ openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
Generating a 2048 bit RSA private key
.....................................................................+++
................................................................+++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:JP
State or Province Name (full name) [Berkshire]:Saitama(都道府県を英字で入力)
Locality Name (eg, city) [Newbury]:Saitama-shi(市区町村を英字で入力)
Organization Name (eg, company) [My Company Ltd]:Slogical Corporation(組織名を英字で入力)
Organizational Unit Name (eg, section) []:System Team(部署名を英字で入力)
Common Name (eg, your name or your server's hostname) []:www.slogical.co.jp(コモンネームを英字で入力)
Email Address []:(空白、エンターのみ入力)

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(空白、エンターのみ入力)
An optional company name []:(空白、エンターのみ入力)
$

OpenSSLでCSR作成(秘密鍵にパスフレーズを設定する)

次の順に opensslコマンドを実行してCSRを作成します。

1. 秘密鍵の作成

$ openssl genrsa -des3 2048 > server.key

(server.key として 2048bitの秘密鍵が生成されます)

2. 秘密鍵を元にCSR作成

$ openssl req -new -key server.key -out server.csr -sha256

(server.csr として CSRが出力されます)

3. 秘密鍵にパスフレーズを埋め込む

$ openssl rsa < server.key > server_withpass.key

(server_withpass.key として、パスフレーズの埋め込まれた秘密鍵が出力されます)
※パスフレーズの埋め込まれた秘密鍵を使用すると、 Apacheの起動時にパスフレーズの入力を省略できます。

実行例

$ openssl genrsa -des3 2048 > server.key
Generating RSA private key, 2048 bit long modulus
.......+++
...........................................................+++
e is 65537 (0x10001)
Enter pass phrase:(パスフレーズ入力)
Verifying - Enter pass phrase:(パスフレーズ入力)
$

$ openssl req -new -key server.key -out server.csr -sha256
Enter pass phrase for server.key:(パスフレーズ入力)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:JP
State or Province Name (full name) [Berkshire]:Saitama(都道府県を英字で入力)
Locality Name (eg, city) [Newbury]:Saitama-shi(市区町村を英字で入力)
Organization Name (eg, company) [My Company Ltd]:Slogical Corporation(組織名を英字で入力)
Organizational Unit Name (eg, section) []:System Team(部署名を英字で入力)
Common Name (eg, your name or your server's hostname) []:www.slogical.co.jp(コモンネームを英字で入力)
Email Address []:(空白、エンターのみ入力)

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(空白、エンターのみ入力)
An optional company name []:(空白、エンターのみ入力)
$

$ openssl rsa < server.key > server_withpass.key
Enter pass phrase:(パスフレーズ入力)
writing RSA key
$

↑ 上へ 注文 検索