Sudoers file syntax error on WSL
So, I've messed up my sudoers file in the windows subsystem for linux. I was trying to add something, and the guy of the tutorial said to edit sudoers file with nano/vim, and that's what I did (later I discovered that you should only edit it with visudo, nice). When I saved, I realized I couldn't use "sudo" anymore, the terminal would complain saying:
>>> /etc/sudoers: syntax error near line 33 <<<
sudo: parse error in /etc/sudoers near line 33
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
I've read a bunch of articles saying that I would have to run:
pkexec /usr/sbin/visudo
But the result was always the same:
Error getting authority: Error initializing authority: Could not connect: No such file or directory
I tried everything, spent like two hours reading stuff and couldn't do anything. Can anyone help me? As you can see, I'm clearly new when it comes to real linux.
Solution 1:
I found quite a simple solution for my case.
Just open Windows console (cmd), then:
wsl -u root visudo
And fix the file.
Note that visudo
does not catch all errors. To avoid getting locked out of sudo
, keep a root shell (sudo -s
) or visudo
open until after you've thoroughly tested your new config.