LoginSignup
3
3

More than 5 years have passed since last update.

Windowsパスワード復号用の鍵ペアを全リージョンで共通化する

Last updated at Posted at 2015-03-04

AWS EC2のWindowsインスタンスのAdministratorパスワードはKey Pairを使って復号するが、
マネージメントコンソールでKey Pairを作成すると、リージョンごとに鍵がバラバラになって管理が面倒。

そこで、手元で作成した公開鍵を全リージョンにインストールすることにする。

手順

まず秘密鍵と公開鍵のペアを作成。マネージメントコンソールに貼り付けるため、パスフレーズは空にする。

cd ~/.ssh
ssh-keygen -b 2048 -t rsa -C "windows only" -N "" -f windows.pem

作成されたキーを全リージョンにimportする。

#!/bin/bash
for region in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do
  echo $region
  aws --region $region ec2 import-key-pair --key-name windows --public-key-material file://~/.ssh/windows.pub
done

注意点

この秘密鍵はパスフレーズで保護されていないので、セキュリティレベルが低い。
LinuxインスタンスのSSH鍵には使わないこと。

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