Unable to reset /etc/sudoers file permissions on EC2 instance even after trying amazon’s procedure

I’m on an amazon ec2 instance. I ran a script that inadvertently changed the owner of the /etc/sudoers files. Now I can not longer run any commands with sudo. Root does not have a password so I can’t log in with that.

I followed the instructions at https://aws.amazon.com/premiumsupport/knowledge-center/ec2-sudo-commands/ which have you upload a bash script that I assume runs upon reboot. However, after rebooting the machine, the permissions on the /etc/sudoers file are still owned by admin, not root.

Anyone know what I can do to get this script to work? I’m running debian version 10 (buster).

Answer

OK, I took a closer look at the bash script that amazon has and it does not change the ownership on the file. The fix is simple. Add the following line to the end of the script (above the --// boundary):

/bin/chown root:root /etc/sudoers

Attribution
Source : Link , Question Author : StevieD , Answer Author : StevieD

Leave a Comment