0
0

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 1 year has passed since last update.

EC2 のホスト鍵を確認して接続する

Posted at

SSH で EC2 に接続する時の下記質問に、いままで脳死で yes とタイプしていました。

$ ssh ec2-user@ec2-54-249-223-3.ap-northeast-1.compute.amazonaws.com
The authenticity of host 'ec2-54-249-223-3.ap-northeast-1.compute.amazonaws.com (54.249.223.3)' can't be established.
ED25519 key fingerprint is SHA256:lISji9JlND8QcBs4aBHuo/JKmZe3ctYqMe/QTg96Rj0.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

しかし冷静に考えると、経路上にどんな人がいるかわかりません。私が接続しようとしているのは本当に EC2 のサーバーでしょうか? もしかすると攻撃を仕掛けている悪意ある人物のサーバーかもしれません。

きちんと確認して接続する方法を調べたところ、コンソールにフィンガープリントが出力されていることがわかりました。したがって、たとえば、マネジメント コンソールで EC2 を開き、アクション > モニタリングとトラブルシューティング > システムログを取得 で表示して確認することができます。マネジメント コンソールには SSL で接続しているので、正しい情報が表示されているはずです1

ec2_console.png

起動直後のログに、以下のようにフィンガープリントが記されています。

<14>Apr  6 08:09:41 cloud-init: #############################################################
<14>Apr  6 08:09:41 cloud-init: -----BEGIN SSH HOST KEY FINGERPRINTS-----
<14>Apr  6 08:09:41 cloud-init: 256 SHA256:eUYB7QLKvMP1FXzsLqJB1cCJ+8HRIYCn8PYxeKyjL+8 root@ip-172-31-31-43.ap-northeast-1.compute.internal (ECDSA)
<14>Apr  6 08:09:41 cloud-init: 256 SHA256:lISji9JlND8QcBs4aBHuo/JKmZe3ctYqMe/QTg96Rj0 root@ip-172-31-31-43.ap-northeast-1.compute.internal (ED25519)
<14>Apr  6 08:09:41 cloud-init: -----END SSH HOST KEY FINGERPRINTS-----
<14>Apr  6 08:09:41 cloud-init: #############################################################

先ほどの質問には yes と答えるのではなく、以下のようにログからフィンガープリントをコピペすることで、安全に known hosts に追加することができます。

Are you sure you want to continue connecting (yes/no/[fingerprint])? SHA256:lISji9JlND8QcBs4aBHuo/JKmZe3ctYqMe/QTg96Rj0
Warning: Permanently added 'ec2-54-249-223-3.ap-northeast-1.compute.amazonaws.com' (ED25519) to the list of known hosts.

これで安全に接続を確立することができました。

なお、この手順は公式ドキュメントにオプションとして記載されているので、やらなくても安全性はほとんど損なわれないのかもしれません。

一方で、Windows インスタンスの場合は、自己署名証明書の拇印 (フィンガープリント) の確認はオプションとはなっていません。

参考

  1. SSL でも不適切なルート証明書を導入してしまうと中間者攻撃に脆弱になります。職場では SSL インスペクションのために追加のルート証明書を導入していますが、こうした場合には証明書の発行元が信頼できるかよく吟味する必要があります。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?