Ubuntu – Everytime I use a sudo command it says “>>> /etc/sudoers.d/90-cloudimg-ubuntu: syntax error near line 1 <<<”

command linesudo

I got the following error while using the sudo apt-get update command.

>>> /etc/sudoers.d/90-cloudimg-ubuntu: syntax error near line 1 <<<
sudo: parse error in /etc/sudoers.d/90-cloudimg-ubuntu near line 1
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

See screenshot

I tried finding a solution, the end of the file is already

#includedir /etc/sudoers.d

You can view the output for pkexec visudo in this screenshot

You can view the file etc/sudoers:

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

#

Please consider adding local content in /etc/sudoers.d/ instead of

directly modifying this file.

#

See the man page for details on how to write a sudoers file.

# Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Host alias specification

User alias specification

Cmnd alias specification

User privilege specification

root ALL=(ALL:ALL) ALL

Members of the admin group may gain root privileges

%admin ALL=(ALL) ALL

Allow members of group sudo to execute any command

%sudo ALL=(ALL:ALL) ALL

See sudoers(5) for more information on "#include" directives:

includedir /etc/sudoers.d

and the file etc/sudoers.d/README

#
# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on
# installation of the package now includes the directive:
# 
#   #includedir /etc/sudoers.d
# 
# This will cause sudo to read and parse any files in the /etc/sudoers.d 
# directory that do not end in '~' or contain a '.' character.
# 
# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.
# 
# Note also, that because sudoers contents can vary widely, no attempt is 
# made to add this directive to existing sudoers files on upgrade.  Feel free
# to add the above directive to the end of your /etc/sudoers file to enable 
# this functionality for existing installations if you wish!
#
# Finally, please note that using the visudo command is the recommended way
# to update sudoers content, since it protects against many failure modes.
# See the man page for visudo for more information.
#

and the output for pkexec cat /etc/sudoers.d/90-cloudimg-ubuntu :

$(user) ALL=(ALL) NOPASSWD:ALL

EDIT: Now I get the following errors-

screenshot

I want a specific and precised answer. I am new to Ubuntu (14.04), please help me!

Best Answer

First of all, never edit /etc/sudoers manually, always use visudo. Your problem was a syntax error in the file /etc/sudoers.d/90-cloudimg-ubuntu but it is now a malformed /etc/sudoers.

So, to fix it (now that you have removed any changes you may have made), run pkexec visudo and make the file look like this:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

    # Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

Save the file (Ctrl+O) and exit (Ctrl+X). Next, I suggest you just move the /etc/sudoers.d/90-cloudimg-ubuntu somewhere else so it doesn't cause issues:

pkexec mv /etc/sudoers.d/90-cloudimg-ubuntu ~/

At this point, you should have a working sudo. If the 90-cloudimg-ubuntu file was necessary, ask a new question with the contents of that file an we can help you put it back and fix the error.

Related Question