Lightsail "sudo: no valid sudoers sources found, quitting"

0

Hi,

I did a mistake on my Lightsail instance running Ubuntu 18.04 and change the sudoers file - now I get this:

sudo: parse error in /etc/sudoers near line 21

sudo: no valid sudoers sources found, quitting

sudo: unable to initialize policy plugin

How can I gain again access to "sudo"?

Is there an option to ssh to the instance as root?

Is there a way to attach the volume to the working machine and change "sudoers"?

Any other option?

Thanks

Avner

Avner
已提問 2 年前檢視次數 228 次
2 個答案
1
已接受的答案

I FIXED IT! You basically build an instance from a snapshot, but add a launch script which runs as root to change the permissions on your sudoers file. Then you can edit sudoers as a non root user. Then you make another snapshot instance with another launch script that sets the permissions back to normal.

  1. create a snapshot of your instance
  2. create a new instance from the snapshot, but click on the +Add Launch Script
  3. add the following launch script: chmod 777 /etc/sudoers
  4. Connnect to the instance and modify your sudoers file back too normal (you may have to wait a few seconds for the launch script to apply the permission change)
  5. reboot
  6. create a snapshot of the instance
  7. create another instance from the new snapshot, click on +Add Launch Script
  8. add the following launch script: chmod 440 /etc/sudoers
  9. Connect to the instance and test sudo -s (you may have to wait again for the launch script to apply the permission change)
  10. Detach IP from original instance. Attach to new instance
  11. Reset all firewall rules
  12. Delete other instances
mcaramb
已回答 2 年前
  • Worked perfectly - Thanks!

0

oh man that's a weird coincidence, I just did exactly the same thing tonight! I mangled my sudoers file cause I forgot I was supposed to use visudo not nano. Watching this for answers...

mcaramb
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南