Accidentally change ownership of /etc/sudoer back to ec2-user

0

Got this error when trying to change it back to root. What is the best way to fix it, best if there's no need to reboot server. Thanks in advanced for willing to assist on it!

Note:

  • root does not set with password, so unable to su -
  • unable to install pkexec now as it require sudo
$sudo chown root:root /etc/sudo.conf
sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

Uname

uname -a
Linux xxx.amzn2.x86_64 #1 SMP Fri Feb 4 17:12:04 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
demandé il y a 2 ans964 vues
2 réponses
0

From aws console > instance > connect user: change to "root" > connect

chown root:root /etc/sudo.conf
chown root:root /etc/sudoers
chown -R root:root /etc/sudoers.d

Now you should be able to run sudo command using ec2-user account

kenng
répondu il y a 2 ans
0

From aws console > instance > connect user: change to "root" > connect

This ^ is inaccessible for me.

Alternative method:

https://aws.amazon.com/premiumsupport/knowledge-center/ec2-sudo-commands/ - I used the "Debian-based" script, but their commands are incomplete.

I simply added (to the bottom) the commands that @kenng provided, and that worked for those specific files & folders. However, in my case I also needed to add:

chown root:root /usr/libexec/sudo
chown -R root:root /usr/libexec/sudo/sudoers.so
User21
répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions