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).

  • Mount the root volume, then ensure that all is well with your public key in the AMI.
    – EEAA
    Jul 13 '15 at 22:53
  • ~/.ssh/authorized_keys has entries for the original key, and the second key I attempted to assign through the EC2 console in there. Where else could / should I be looking? Jul 13 '15 at 23:08
  • My problem may reduce to "How can I setup password login on an EC2 instance when I only have filesystem access?" Jul 13 '15 at 23:15

If rebooting the system is not an issue you could try to reboot into single user mode, this answer explains how to do it using GRUB2 as the boot loader.

If you have another system and the root filesystem of the broken instance is available/mountable you could try to mount it from the working system then use

chroot /path/to/root/fs

Once you have done that you should be able to make changes to the relevant configurations, change passwords, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.