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:
- Stop (don't terminate) the original instance
- Detach the EBS volume
- Launch another instance
- Attach your current EBS volume to the new instance
- SSH into the new instance, mount the EBS volume and make the needed changes
- Unmount the EBS volume (e.g.
umount -d /dev/xvdh
or umount -d /dev/sdh
)
- Detach the EBS volume from new instance and attach it as the root volume (e.g.
/dev/sda1
) of the old instance
- Start the old instance
- If everything is working, terminate the new instance
The 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.
visudo
(sorry - doesn't help now, i know, but it may avoid a repeat).visudo
only checks the syntax of the/etc/sudoers
file but not the logic. You can still lock yourself out withvisudo
. Keep a root session open until you have tested your new configuration.