1

I made the following change in the file /etc/sudoers:

sudo  ALL=(ALL) NOPASSWD:ALL

And now I can't use sudo and can't edit /etc/sudoers anymore:

/etc/sudoers: near line syntax error 31 <<<
sudo: parsing error in /etc/sudoers near line 31
sudo: no valid sudoers source found; going out
sudo: unable to initialize policy plugin

Is there a way to solve this problem or will I have to format my ubuntu 20.04?

  • 4
    If you can boot from a USB, you could mount the disk, find the 'bad' file and edit the line so that it reads correctly. I would eliminate the new line, and in the future, I would use sudo visudo to edit the file: you can also do sudo visudo -f /path/to/file when fixing your current file. – Charles Green Feb 04 '22 at 20:00
  • The first error in the /etc/sudoers file becomes the EOF (end-of-file) marker; which is why the visudo command exists; ie. it will validate for errors & let you correct before exit if error(s) exist. FYI: yeah it's visudo but it will use whatever editor you've told it to, which may not be vi – guiverc Feb 04 '22 at 21:06
  • 1
    If it's a desktop system, and you're logged in locally, you may be able to use pkexec visudo. See for example How to modify an invalid '/etc/sudoers' file? – steeldriver Feb 04 '22 at 21:20
  • 1
    This problem is why one Always has a root shell open on another tetminal/ssh session when one is futzing with authentication stuff. This gives one a chance of recovery without booting from a Live USB. – waltinator Feb 04 '22 at 23:21

0 Answers0