I managed to save my sudoers file with a syntax error so now I can't do sudo -i any more on my EC2 instance.

This effectively locks me out of root account since the only way to get root access on EC2 is via sudo.

How can I fix this?


You need to spawn a new EC2 instance (minimal size will do), and make sure you can log in via SSH and sudo into the new instance.

After that, shut down the current instance and detach virtual disk.

Shut down also the newly spawned EC2 instance, and attach the virtual disk as secondary disk on that instance, and boot it.

After the boot, mount the root partition of old drive, fix sudo file, shut down, detach disk, attach it back to original VM, and boot it.

It's not a simple procedure, but I did it couple of times.

|improve this answer|||||

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.