Member-only story
Re-using EC2 SSH Key Pair in multiple AWS regions
One of the parameters required for launching an EC2 instance is a Key Pair which is effectively an SSH Key used for interactive logging into the default user account — on Amazon Linux it’s the ec2-user account — or for decrypting the Windows Administrator’s password.
It is easy to create a new Key Pair / SSH Key as part of the EC2 launch process however as soon as you start using more regions and more accounts you will quickly end up with heaps different Keys and unless you are diligent with their naming both on the filesystem and in AWS you will end up with a mess. Like I used to.
Fortunately there is a way to re-use an existing Key Pair in other regions or even in other AWS accounts. And it’s actually pretty easy.
Before we start I assume you’ve got an existing Key Pair or SSH Key stored in a PEM file. Either one created in the AWS EC2 console, or your own usual SSH Key created using ssh-keygen
. Either will work. Let’s say it’s saved as ~/.ssh/michael.ludvig-key.pem
.