使用sudo apt-get update命令时出现以下错误。
>>> /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
Run Code Online (Sandbox Code Playgroud)
我试图找到一个解决方案,文件末尾已经
#includedir /etc/sudoers.d
Run Code Online (Sandbox Code Playgroud)
您可以在此屏幕截图中查看输出pkexec visudo
您可以查看文件 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
Run Code Online (Sandbox Code Playgroud)
和文件 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.
#
Run Code Online (Sandbox Code Playgroud)
和输出pkexec cat /etc/sudoers.d/90-cloudimg-ubuntu:
$(user) ALL=(ALL) NOPASSWD:ALL
Run Code Online (Sandbox Code Playgroud)
编辑:现在我收到以下错误-
我想要一个具体而准确的答案。我是 Ubuntu (14.04) 的新手,请帮助我!
首先,永远不要/etc/sudoers手动编辑,总是使用visudo. 您的问题是文件中的语法错误,/etc/sudoers.d/90-cloudimg-ubuntu但现在是格式错误的/etc/sudoers.
因此,要修复它(现在您已经删除了您可能所做的任何更改),请运行pkexec visudo并使文件如下所示:
#
# 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
Run Code Online (Sandbox Code Playgroud)
保存文件 ( Ctrl+ O) 并退出 ( Ctrl+ X)。接下来,我建议您将其移动到/etc/sudoers.d/90-cloudimg-ubuntu其他地方,以免引起问题:
pkexec mv /etc/sudoers.d/90-cloudimg-ubuntu ~/
Run Code Online (Sandbox Code Playgroud)
此时,您应该有一个可以工作的sudo. 如果需要该90-cloudimg-ubuntu文件,请提出有关该文件内容的新问题,我们可以帮助您将其放回原处并修复错误。