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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠