How to fix /etc/sudoers: syntax error near line number
Asked Answered
A

4

6

I am new to Ubuntu. And as while editing anything in visual studio code, I had to enter password. so for that I tried to change in sudoers file but after that I am unable to find what happened and also getting error like below.

I used the command to change i

sudo nano -w /etc/sudoers

after which i pressed ctrl+x

/etc/sudoers: syntax error near line 26 <<<
sudo: parse error in /etc/sudoers near line 26
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

Thank you.

Atomy answered 2/10, 2019 at 4:41 Comment(0)
A
3
we have to write -
pkexec visudo
And it will open the file and one need to change as previous if any made.
Then type Ctrl+X which will ask to save the file. So type: Y and Enter
Atomy answered 2/10, 2019 at 10:32 Comment(1)
🀝🏻 thx, useful compare to reboot in recovery mode red-tape procedures... – Kierkegaard
C
9

Edit:

On your terminal type:

pkexec nano /etc/sudoers

It will open the file and you can edit now. To save and exit the file, just press:

Ctrl+X

And it will ask you if you wanna save the file. So type: Y and Enter. Done!!!

Coffeng answered 2/10, 2019 at 4:54 Comment(7)
I am not getting you. can u plz tell me what is editor_of_choice? – Atomy
I just edited my answer. Hope it helps. Let me know if you have any further questions :) – Coffeng
ok. Thank you. I have noted it down. but problem is I am unable to use sudo and whille using this, I am getting the above syntax error. – Atomy
Your question is already asked before. For detailed explanation please take a look at this and this links – Coffeng
sherzod, while using the above command u mentioned, m getting the same error as - /etc/sudoers: syntax error near line 26 <<< sudo: parse error in /etc/sudoers near line 26 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin – Atomy
now it opens with pkexec visudo , can u plz tell me how to save changes and exit it. i am trying but not getting success. – Atomy
🀝🏻 thx, useful compare to reboot in recovery mode red-tape procedures... – Kierkegaard
A
3
we have to write -
pkexec visudo
And it will open the file and one need to change as previous if any made.
Then type Ctrl+X which will ask to save the file. So type: Y and Enter
Atomy answered 2/10, 2019 at 10:32 Comment(1)
🀝🏻 thx, useful compare to reboot in recovery mode red-tape procedures... – Kierkegaard
R
0

This should open visudo up in nano.

$ export EDITOR=nano && sudo -E visudo
Radiometer answered 2/10, 2019 at 4:59 Comment(2)
After this what should I do ? as when trying to use sudo command I am getting above error. – Atomy
Ahh sorry my mistake, I thought that it wasn't opening correctly. In the case of a corrupt sudoers file I believe that is best answered here: link – Radiometer
R
-2

If you are using WSL 2 (Windows Subsystem for Linux 2) for Ubuntu 20.04 LTS, and you encounter issues with the sudoers file, you can follow these steps to resolve the problem: Open a new Command Prompt or PowerShell window. Run the following command to access the WSL shell as the root user:

wsl -u root

-Editing sudoers File: nano /etc/sudoers

Correcting Syntax Error:

**Navigate to the line mentioned in the error message. Correct the syntax error. Pay attention to the correct syntax for sudoers file entries. Exit Root Shell:

Ctr+X Ctr+Y Enter

Test whether sudo is working again sudo ls

voila, sudo is rectified.

Rhetic answered 6/10, 2023 at 1:2 Comment(3)
Never edit /etc/sudoers using anything other than the visudo command – Pashalik
Sometimes the visudo command can't work if your /etc/sudoers has some bugs. That is for those using Ubuntu WSL – Rhetic
Unless you can provide some evidence, that's garbage. visudo provides a safety net when editing sudo policies. It checks to make sure the file is valid. That's an important part of the application, and it's the only way you should edit the sudoers file. A broken visudo means a broken sudo package – Pashalik

© 2022 - 2024 β€” McMap. All rights reserved.