Connect an already existing EC2 instance with a new ssh key pair - AWS

0 votes
I have an already running EC2 instance. But the problem is that I lost the old ssh key pair and now I'd like to attach the new ssh key pair to this running instance. Is this possible? If yes how?
Oct 17 in AWS by Hannah
• 16,210 points
147 views

1 answer to this question.

0 votes

yes, this is possible. Follow the below mentioned steps @Hannah:

  • Create a new ssh key pair
  • Stop the running instance
  • Go to Actions -> Instance Settings -> View/change user data
  • Add the following script
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: 
    - ssh-rsa keypair
  • Add your username in the username sections and replace the key pair with the new key pair and click on Save.

answered Oct 17 by Rick

Related Questions In AWS

0 votes
3 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer