I edited my Linux Amazon EC2 instance using vim /etc/sudoers and tried adding another account to the list. I realize now that this was a terrible mistake. I can no longer sudo from any account (which means I cannot edit the file again) and I do not have the root account password. Is there anything I can do to correct this?
Thanks.
Best Answer
Hopefully you are using an EBS root volume. If so, the solution is not too difficult.
Essentially, you attach the EBS volume to another instance make the changes, and reattach it to the original instance:
umount -d /dev/xvdh
orumount -d /dev/sdh
)/dev/sda1
) of the old instanceThe reason this works, is that on the fresh, new instance, you have the proper permissions - its root volume is intact - which makes the sudoers file from your original instance just another file you can edit.
If you have an instance-store root volume, unfortunately, you probably won't be able to fix the problem, and will have to revert to an AMI you have made previously as a backup.