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
posta 2 anni fa228 visualizzazioni
2 Risposte
1
Risposta accettata

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
con risposta 2 anni fa
  • 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
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande