Ubuntu 22.04にmkcertをインストールしてローカル証明書を作成する

概要

場合に役立つコマンド、mkcertをインストールします。

インストール方法

aptitude (apt)によるインストール

sudo aptitude install mkcert

ローカルルート証明書を作成

mkcert -install
ls -l ~/.local/share/mkcert/

ホスト名に追記・修正

ファイル /etc/hosts をルート顕現で、以下のように修正します。

127.0.0.1  agnes-luce

※ Ubuntu系はホスト名に指定したIPがなぜか127.0.1.1になっています。

証明書作成

cd /hoge && pwd

任意のディレクトリに移動します。

mkcert -key-file ドメイン名.key.$(date +%Y%m) -cert-file ドメイン名.crt.$(date +%Y%m) ドメイン名
mkcert -key-file agnes-luce.key.$(date +%Y%m) -cert-file agnes-luce.crt.$(date +%Y%m) agnes-luce
Created a new certificate valid for the following names 📜
 - "agnes-luce"

The certificate is at "agnes-luce.crt.202404" and the key at "agnes-luce.key.202404" ✅

It will expire on 14 July 2026 🗓

証明書の整合性を確認

openssl x509 -pubkey -in 証明書ファイル -noout | openssl md5
openssl pkey -pubout -in 秘密鍵ファイル | openssl md5

それぞれのハッシュ値が同じであることを確認します。

こうしてできた一式は2年半有効です。


Revision #2
Created 14 April 2024 14:48:54 by manualmaton
Updated 14 April 2024 15:18:20 by manualmaton