Can't use sudo

After I edited the /etc/sudoer.d/my_sudoers file with nano I was unable to use sudo.

The following errors are giving when trying to use sudo.

sudo: parse error in /etc/sudoers.d/my_sudoers near line 4
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

I know exactly what is wrong but I have no way to edit the file since it is owned by root.

I can't use chown to change the ownership because that would involve using sudo.

Pkexec has not been installed or configured on the server so I'm not sure if that is an option.

I have tried using the copy command to make a back up but I get the same errors.

Can someone please tell me how to solve this?

Please don't recommend reboot the server because that is not an option.

3 Replies

@LowerMedia:

After I edited the /etc/sudoer.d/my_sudoers file with nano I was unable to use sudo.

The following errors are giving when trying to use sudo.

sudo: parse error in /etc/sudoers.d/my_sudoers near line 4
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

I know exactly what is wrong but I have no way to edit the file since it is owned by root.

I can't use chown to change the ownership because that would involve using sudo.

Pkexec has not been installed or configured on the server so I'm not sure if that is an option.

I have tried using the copy command to make a back up but I get the same errors.

Can someone please tell me how to solve this?

Please don't recommend reboot the server because that is not an option.

Switch to the root user with 'su' and type its password. Or open a SSH connection directly to root. Or use LiSH to directly open a root shell.

If none of these options are viable, I would suggest deleting the /etc/sudoers.d/my_sudoers file via recovery (Finnix)

By the way, I don't know about your distro, but mine says this at the top of /etc/sudoers:
> #

This file MUST be edited with the 'visudo' command as root.

This is why.

Using LiSH to create a root shell worked.

Thank you so much for the help

I'll add that the only way that type of error could happen is if you edit /etc/sudoers directly outside of using visudo. visudo has a validator in it that ensures the file is formatted correctly and prevents syntax errors from causing issues. It still can't prevent mistakes from happening… Just removes some of the possibilities.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct