いきなり結論
秘密鍵と公開鍵の組み合わせが正しいのかわからなくなったときは下記のコマンドで確認可能です。
diff <(openssl rsa -pubin -noout -modulus -in public.key) <(openssl rsa -noout -modulus -in private.key)
解説
openssl は -modulus
オプションを指定することで rsa modulus という公開鍵の要素が表示されるため、それぞれのファイルの modulus が同じであれば同じ公開鍵ペアであることがわかります。
また、それぞれの実行結果を目で diff をするのはつらく、diff で比較したいですがファイルを一時的に作成するのは面倒なためプロセス置き換えを使って diff に渡しています。
そのほかのファイル(証明書、秘密鍵)も含めた modulus を出力するコマンドは下記のとおりです。
公開鍵
openssl rsa -pubin -noout -modulus -in public.key
秘密鍵
openssl rsa -noout -modulus -in private.key
証明書
openssl x509 -noout -modulus -in example.com.cer
CSR
openssl req -noout -modulus -in example.com.csr