Sunday, January 26, 2014

Recover unreachable EC2 CentOS instance

So .. I was working for three days setting up a CentOS ec2 instance environment, and I was using root credentials to login into the VM. 

I decided to stop using password and start using SSH Keys since I am going to share the VM with other developers. So I setup the ssh authorized keys properly and dropped the root password but I forgot to tweak ssh configuration to permite Empty Passwords! and I got stuck outside the VM with password prompt that does not accept any single damn word! :)

So, the simplest solution I found on the internet was to mount the volume to another ec2 instance, fix the password settings and put it back to the unreachable ec2 instance.

Here are the steps :

  • First you need to setup Amazon ec2 API tool
  • Get instance id from ec2
  • Get volume id from ec2
  • Stop the unreachable instance
  • Detach the volume from unreachable instance
  • Start the debugger instance
  • attach the volume to the debugger instance
  • ssh the debugger instance
  • mount the volume
  • fix the ssh setting to enable/permits empty passwords
  • unmount the volume
  • detatch the volume from the debugger instance
  • attach the volume to the unreachable instance
  • now try to ssh, if it did not work you need to repeat the steps and keep fixing the configs until it works.
 I will try to edit this post to provide more details soon. But for now, hope this helps you to fix your problem, you can leave a comment if you need any help!