Cannot edit invalid sudoers file, getting parse error

Case: After creating a file in /etc/sudoers.d/ and adding command aliases and a user privilege specification, the file became inaccessible and sudo-ing no longer worked on Ubuntu.

Solution

Use pkexec instead sudo when accessing the file.
pkexec allows an authorized user to execute PROGRAM as another user.”

For example, use:

pkexec visudo -f /etc/sudoers

instead of:

sudo visudo -f /etc/sudoers

Same goes for visudo -f /etc/sudoers.d/some_file.

References

  1. sudo – How to modify an invalid “/etc/sudoers” file? – Ask Ubuntu
  2. pkexec(1) – Linux man page

Was this post helpful?