Bad edit to sudoers file on EC2 instance, how to fix it? While writing a script to edit the sudoers file without using visudo, the script did not check for issue, and I have introduced some bad edits into the sudoers file, and thus cannot use sudo at all anymore. (I know I did a very bad thing, and should probably have used something like this)

Question: Is there anyway I can recover from this mistake, or do I have to destroy the VM and start from scratch with a new one?
How about user-data ?

I believe adding the "#cloud-boothook" allow to force the user-data to run at every restart.

#cloud-boothook
#!/bin/bash
echo 'test' &gt; /home/ec2-user/user-script-output.txt


If so, you could fix your sudo scripts hopefully... or install / add AWS run commands configuration https://aws.amazon.com/blogs/aws/new-ec2-run-command-remote-instance-management-at-scale/

For sure if it is an EBS Drive, you can detach &amp; fix and then re-attach on the original system. A bit of a pain though.