我在使用该命令时出现以下错误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
我尝试寻找解决方案,文件末尾已经
#includedir /etc/sudoers.d
您可以查看以下输出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
以及文件 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.
#
输出为pkexec cat /etc/sudoers.d/90-cloudimg-ubuntu
:
$(user) ALL=(ALL) NOPASSWD:ALL
编辑:现在我收到以下错误-
我想要一个具体而精确的答案。我是 Ubuntu (14.04) 新手,请帮帮我!
答案1
首先,/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
保存文件(Ctrl+ O)并退出(Ctrl+ X)。接下来,我建议您将其移动到/etc/sudoers.d/90-cloudimg-ubuntu
其他地方,以免引起问题:
pkexec mv /etc/sudoers.d/90-cloudimg-ubuntu ~/
此时,您应该有一个可以工作的sudo
。如果该90-cloudimg-ubuntu
文件是必需的,请提出一个包含该文件内容的新问题,我们可以帮助您将其放回原处并修复错误。