Friday, August 29, 2014

Amazon EC2 - I messed up system file and can't login or fix it

So you tried to be smart ..that's good but you didn't plan ahead

Unix is an OS that can be error intolerant and you can loose the access to your system with a simple change on a file like /etc/sudoers  this file contains infromation and password configuration to ask for password on some commands.

In Amazon EC2 you don't have root password so if you configure that file to require password on some commands like 'sudo' command itself that is required to access this file, you will be locked and can't revert back to the changes.

there is a way though to go around this problem, and basically it's by creating a new instance and attach the broken instance volume to this instance as device and fix what's wrong then relaunch your broken instance.

for example to fix a change on sudoers file with this solution follow the following steps:

1- stop instance we want to fix

2- de-attach it's volume

3- attach it to the new instance [/dev/sdh]

4- start new instance

5- connect with putty

6- create directory to mount 

7- sudo mount device_name mount_point

8- cd [mount_point] > cd etc > vi sudoers

9- modify the file to revert your changes

10- save, exit

11- unmount volume : umount -l [mount_point]

12- stop instance & deattach volume

13- attach to broken instance

14- launch broken instance


Hope this helps!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Istio —simple fast way to start

istio archeticture (source istio.io) I would like to share with you a sample repo to start and help you continue your jou...