HiveBrain v1.2.0
Get Started
← Back to all entries
debugMinor

Bad edit to sudoers file on EC2 instance, how to fix it?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
fixeditfilesudoersec2badinstancehow

Problem

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?

Solution

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' > /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 & fix and then re-attach on the original system. A bit of a pain though.

Code Snippets

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

Context

StackExchange DevOps Q#1594, answer score: 5

Revisions (0)

No revisions yet.