If you lose your EC2 key pair, you can register another key pair with your existing instance. You don't have to create a new instance.
The procedure for linux / MacOS is shown as an example.
Creating a new key pair is not mandatory. Skip if you want to use another existing key pair.
> Go to
Network & Security>
Key Pair` $ mv xxxxx.pem ~/.ssh/
$ chmod 400 ~/.ssh/xxxxx.pem
$ ssh-keygen -y -f ~/.ssh/xxxxx.pem
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe53pcjqP3maAhDFcvBS7O6V
hz2ItxCih+PnDSUaw+WNQn/mZphTk/a/gU8jEzoOWbkM4yxyb/wB96xbiFveSFJuOp/d6RJhJOI0iBXr
lsLnBItntckiJ7FbtxJMXLvvwJryDUilBMTjYtwB+QhYXUMOzce5Pjz5/i8SeJtjnV3iAoG/cQk+0FzZ
qaeJAAHco+CY/5WrUBkrHmFJr6HcXkvJdWPkYQS3xqC0+FmUZofz221CBt5IMucxXPkX4rWi+z7wB3Rb
BQoQzd8v7yeb7OzlPnWOyN0qFU0XA246RA8QFYiCNYwI3f05p6KLxEXAMPLE
Action
> Instance Settings
> ʻEdit user data`
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [users-groups, once]
users:
- name: username
ssh-authorized-keys:
- PublicKeypair
Modify * ** users.name ** and ** PublicKeypair ** and click "Save"
users.name ... ec2-user etc
PublicKeypair ... The public key you just created
Launch an instance
After booting, check that you can ssh connection using the downloaded pem file
ssh -i ~/.ssh/xxxxx.pem [email protected]
Stop the instance
Delete all the scripts pasted earlier, including the public key
Paste the saved user data if it exists
Click "Save"
Launch an instance
[How do I connect to my Amazon EC2 instance if I lose my SSH key pair after the first boot?](Https://aws.amazon.com/jp/premiumsupport/knowledge-center/user-data-replace -key-pair-ec2 /)
Recommended Posts