Something bizarre happened to an Ubuntu EC2 instance of mine - while it used to have a keypair assigned for login that worked fine (created through the default EC2 console channels), the assigned keypair "disappeared" from the EC2 console (it now says no keypair assigned), and login attempts now result in a "No supported authentication methods available (server sent public key)" error in PuTTY and a simple connection time out from my desktop linux machine.
So, I made an AMI from the instance, and booted up a new instance from that AMI with a new keypair assigned, and I also cannot SSH into the new instance!
I mounted the root volume from a secondary instance and checked .bash_history and sshd_config, and nothing seems out of the ordinary or different from a default EC2 setup.
Bizarrely, I can add a hashed password entry for the ubuntu user on the mounted disk and allow password auth in sshd_config, and I can then reboot the instance and log in through password SSH - but then when I try to create an AMI from this "fixed" password log in instance, and boot up again, it no longer accepts the password!
All of the instances involved in this test have the same security group, open for the SSH group. I cannot explain most of the instance's behavior in this conundrum.
What are my options? How could I "completely reset" whatever bizarre thing is happening to SSH with this instance? I tried
sudo apt-get remove --purge openssh-client openssh-server and then reinstalling, without a change in behavior. The setup on the instance is complex, so my goal is to make an AMI from this instance that I can SSH into.
Edit: In the second step, where I try creating an AMI from the original instance and add a new keypair - in the EC2 console there is now a key pair name assigned, but it still doesn't work. The error when I try to do so is:
Permission denied (publickey)..
Edit 2: So, I copied ~/.ssh/authorized keys from a newly created EC2 instance to the boot device of the instance that I can't log into. I also copied the sshd_config from the new EC2 instance. Both instances have the same new key pair assigned to them on the EC2 console, and I'm using the same local private key to connect to both. Both only have an ubuntu user with no password in /etc/shadow, and passwordauth disabled in sshd_config. One works, and the other still returns
Permission denied (publickey).