1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

自己証明書自動作成

Last updated at Posted at 2020-05-31

HTTPS通信のテストのため、自己証明書(オレオレ証明書)を使うケースがあるが、
自己証明書を自動的に作成する方法を説明する。

検証環境:Amazon Linux, Amazon Linux2(CentOSやRedHat系もOK)
事前インストールパッケージ:opnessl

openssl確認

[root@localhost tmp]# openssl version
OpenSSL 1.0.1k-fips 8 Jan 2015

opensslのバージョンが表示されたら、OK

証明書作成

[root@localhost tmp]# secretFileName=secret
[root@localhost tmp]# domainName=www.hoge.com
[root@localhost tmp]# email=root@hoge.com

[root@localhost tmp]# openssl genrsa 2048 > ${secretFileName}.key
[root@localhost tmp]# openssl req -new -key ${secretFileName}.key << EOF > ${secretFileName}.csr
JP
Tokyo
Tokyo
hogeCompany
development
${domainName}
${email}


EOF
[root@localhost tmp]# openssl x509 -days 3650 -req -signkey ${secretFileName}.key < ${secretFileName}.csr > ${secretFileName}.crt

opensslで証明書作成時に色々入力を求められるが、EOF入力で自動化している。
気を付けるところは上記の${email}とEOFの間に改行が2行入ること
secretFileNameやdomainName、emailを外部からパラメータとして受け入れるようにすれば、
shellscriptとして使えるので、試してみよう!

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?