Change root’s password when sudoers file is misconfigured and sudo won’t work

If you misconfigure the sudoers file you may end up in a situation where you wouldn’t be able to use sudo. This could be easely fixed by just using su to became root and then fixing the sudoers file. But things would be worst if what you wanted to do is change root’s password. You would get an error like this:

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

sudo

Editing the sudoers file with visudo won't work either of course. pkexec can save your day in this situation. This program is used to allow an authorized user to execute a program as another user. If no username is specified then the program will be executed as root.

So the solution is to run visudo using pkexec and fixing the error:

pkexec visudo

You might also like

Use sudo without being asked for your password
Run in a terminal:sudo visudoThe sudoers file will be opened with your default editor. There...

Change root password in MySQL
In GNU/Linux:$ sudo mysqld_safe --skip-grant-tables & $ mysql -u root -p #press enter to use a...

Find the library or program that installs a specific file with apt-file
Sometime you could end up in a situation where you need to know which program or library installs a file....

Change password for postgres user in PostgreSQL
In order to change the password for the postgres user you should NEVER do this:$ sudo passwd postgresBy...

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.