はじめに
昨年、自作Webサーバをhttpsに対応したので、定期的に証明書の更新作業が発生することになりました。たまの作業で忘れそうなので、自分メモとして手順を残したいと思います。
基本情報
- OS:Ubuntu 24.04.1 LTS
- Webサーバ:apache2
- IP:192.168.10.10
- LAN内でのみ使用するサーバのためEASY-RSAでローカルCA署名した証明書を使用
- ディレクトリ:~/easy-rsa
秘密鍵生成
必要に応じで~/easy-rsa/pki/openssl-easyrsa.cnfを変更する。自分の場合は前回と同じ条件にしたいため、そのまま使用。
$ cd ~/easy-rsa/
$ ./easyrsa gen-req myserver03 nopass
Using Easy-RSA 'vars' configuration:
* /home/myuser/easy-rsa/vars
Using SSL:
* openssl OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024)
WARNING!!!
An existing private key was found at /home/myuser/easy-rsa/pki/private/myserver03.key
Continuing with key generation will replace this key.
Type the word 'yes' to continue, or any other input to abort.
Confirm key overwrite: yes
-----
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.
-----
Common Name (eg: your user, host, or server name) [myserver03]:myserver03
Notice
------
Private-Key and Public-Certificate-Request files created.
Your files are:
* req: /home/myuser/easy-rsa/pki/reqs/myserver03.req
* key: /home/myuser/easy-rsa/pki/private/myserver03.key
自作CAで署名
~/easy-rsa/pki/issued/に以前の証明書が残っていたらエラーになるため、削除やリネームをして(コマンド省略)以下を実行します。途中でCAのパスフレーズが聞かれるので、CA生成時に指定したパスフレーズを入力してください。
$ ./easyrsa sign-req server myserver03
Using Easy-RSA 'vars' configuration:
* /home/myuser/easy-rsa/vars
Using SSL:
* openssl OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024)
You are about to sign the following certificate:
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.
Request subject, to be signed as a server certificate
for '825' days:
subject=
commonName = myserver03
X509v3 Subject Alternative Name:
IP:192.168.10.10
Type the word 'yes' to continue, or any other input to abort.
Confirm request details: yes
Using configuration from /home/myuser/easy-rsa/pki/openssl-easyrsa.cnf
Enter pass phrase for /home/myuser/easy-rsa/pki/private/ca.key: →パスフレーズ入力
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'myserver03'
Certificate is to be certified until Mar 23 04:16:26 2028 GMT (825 days)
Write out database with 1 new entries
Database updated
Notice
------
Certificate created at:
* /home/myuser/easy-rsa/pki/issued/myserver03.crt
証明書の内容を確認します。
$ openssl x509 -in ~/easy-rsa/pki/issued/myserver03.crt -text -noout
Validity
Not Before: Dec 19 04:16:26 2025 GMT
Not After : Mar 23 04:16:26 2028 GMT
X509v3 Subject Alternative Name:
IP Address:192.168.10.10
生成した証明書、キーをサーバに配置
必要に応じて既存ファイルはリネームしておき(コマンド省略)、以下を実行して新しいファイルを配置します。
$ sudo cp ~/easy-rsa/pki/issued/myserver03.crt /path/to/crtfile/
$ sudo cp ~/easy-rsa/pki/private/myserver03.key /path/to/keyfile/
Apacheをreload
新しい証明書をApacheに反映させるため、reloadを行います。
$ sudo systemctl reload apache2
一瞬で実行され、反映も即座にされました。
反映の確認
証明書の情報を確認
$ openssl s_client -connect 192.168.10.10:443
省略
---
Certificate chain
0 s:CN = myserver03
i:CN = mycacorp.local
a:PKEY: id-ecPublicKey, 384 (bit); sigalg: ecdsa-with-SHA512
v:NotBefore: Dec 19 04:16:26 2025 GMT; NotAfter: Mar 23 04:16:26 2028 GMT
1 s:CN = mycacorp.local
i:CN = mycacorp.local
a:PKEY: id-ecPublicKey, 384 (bit); sigalg: ecdsa-with-SHA512
v:NotBefore: Aug 19 02:41:19 2025 GMT; NotAfter: Jul 26 02:41:19 2125 GMT
---
省略
証明書の期限等更新されているか確認。
クライアントでブラウザを開き確認
クライアントのブラウザから正常に開けるか、開けたら証明書の内容を確認して新しい情報になっているかを確認。
おわりに
自分メモのため内容が荒いかもしれません。何かお気づきの点があれば可能な限りで修正いたします。