It’s quite common for an administrator to edit sudoers file and allow users to execute administrative commands. But what if you make an error? The sudo command is going to fail isn’t? That’s what exactly I did while installing OpenStack on a Ubuntu machine. Well, here’s what I saw after making a mistake in the sudoers file.
#openstack@devstack:~$ sudo -s >>> /etc/sudoers.d/50_stack_sh: syntax error near line 1 <<< >>> /etc/sudoers.d/50_stack_sh: syntax error near line 2 <<< >>> /etc/sudoers.d/50_stack_sh: syntax error near line 3 <<< sudo: parse error in /etc/sudoers.d/50_stack_sh near line 2 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin
The above error tells us clearly that there is a syntax error on line 1, 2 and 3! To add to this chaos, I did not remember the root password. How scary is that? Of course it’s, but here’s the work around.
Fix errors in sudoers file using pkexec command
Solution: The modern Ubuntu system and many other Linux distributions have made it easy to fix errors in sudoers file. Assuming you are authorized to run programs as root, execute the below command and enter your password. The command pkexec along with visudo will be executed as root and allow you to edit sudoers file.
openstack@openstack-devstack:~$ pkexec visudo -f /etc/sudoers
In my case, /etc/sudoers.d/50_stack_sh file had the syntax error on line 1, 2 & 3. Below is the command to fix the error.
openstack@openstack-devstack:~$ pkexec visudo -f /etc/sudoers.d/50_stack_sh ==== AUTHENTICATING FOR org.freedesktop.policykit.exec === Authentication is needed to run `/usr/sbin/visudo' as the super user Authenticating as: openstack,,, (openstack) Password:
im using aws machine there isno password how can i enter password
Life saver!
Does not work on Linux Mint