I have an ec2-ubuntu instance. And now I forgot the password for the user. Unfortunately i've also lost the .pem file and .ppk file i used to use with putty. And finding it difficult to get in. I want to upgrade some code of mine in that.
I've gone through following links giving suggestions as to what can be done.
aws-gaining-ssh-access-to-an-ec2-instance-you-lost-access-to
add-keypair-to-existing-ec2-instance
locked-myself-out-root-account-ec2-ubuntu-instance
ec2-fix-ebs-root
I've additional constraint that the private i/p address of system should not change.One of the software I'm using uses system private i/p address for license. And currently my instance has only one volume and is root volume.
Based on the links mentioned above, I need to detach my volume and attach to other instance. Make required changes for access. And the reattach to original instance. However since the volume in my case is root volume, I need to stop the instance and then detach it. If my understanding is correct, this can cause change in private i/p address of instance.
Would like to know if there is some thing that can be done? Or following the steps mentioned in links is the only way and then update s/w license on instance restart?
thanks
If your instance is a managed instance in AWS Systems Manager, then use the AWSSupport-ResetAccess document to recover your lost key pair. AWSSupportResetAccess automatically generates and adds a new SSH (public/private) key pair using the EC2 Rescue for Linux tool on the specified EC2 instance.
Note: Stop/Start of EC2 instance will change the IP address (just read that the OP needed the IP to remain unchanged).
This works for me for AWS EC2 Ubuntu 18.04.
ssh-rsa ...
public key into the script below#cloud-config
bootcmd:
- echo 'ssh-rsa AAAAB3Nz...' > /root/.ssh/authorized_keys
#cloud-config
cloud-init-per once
, but never got it working, just wasted a lot of time>>
instead of >
to append the key instead of overwriting the authorized_keys
file. But if you botched the contents during previous attempts, you will never know why it doesn't work.ubuntu
user: echo 'ssh-rsa ...' > /home/ubuntu/.ssh/authorized_keys
authorized_keys
file. For JumpCloud, you could change the script to write to echo 'ssh-rsa ...' > /home/ubuntu/.ssh/authorized_keys.jcorig
(JumpCloud includes the contents of that file)m_ec2.modifyInstanceAttribute(new ModifyInstanceAttributeRequest().withInstanceId("<instance-id>").withUserData(userdataBase64));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With