I use PuTTY to connect to Amazon EC2 instanace, my computer failed and it turns out I didnt have the PuTTY ppk file saved anywhere so I could conect to EC2 from a different computer.
So I followed the instructions at https://repost.aws/knowledge-center/user-data-replace-key-pair-ec2 to create a new Amazon Key Pair and then add it to the user-data of the EC2 instance so that this new pair can be used to connect from PuTTY
It seemed to work, I could login to my EC2 from PuTTY. However I realized i has set name to ec2-user and my actual username on this intance was ubuntu so i didnt login to the correct account and attempts to use su – ubuntu failed as well because dont know the password. So I did the following:
- Shutdown EC2 instance
- Remove user-data
- Restart EC2 instance
- Add user-data again but ensure set name to ubuntu
- Restart EC2 instance
but it doesnt work when I try to connect using puTTY it just complains Server refused our key, what am I doing wrong ?
I then try as an experiment modifying name to rubbish and restarting. This has no effect i couldnt login as rubbish but I could continue to login as ec2-user!
Update
I managed to recover my original .ppk file from my failed drive and so I can now use PuTTY ssh to EC2 using the original key pair.
However, for the benefit of others Im still interested in why the user-data approach doesnt seem to work ?
2
Answers
You can also have an option to create an AMI for that instance and launch the instance from AMi with your selected key.
And you will use ubuntu as your username for login.
Regards
Some ways how to access Amazon EC2 instance if SSH key pair was lost:
https://repost.aws/knowledge-center/user-data-replace-key-pair-ec2