gpt4 book ai didi

linux -/etc/sudoers 文件有问题但无法访问 root

转载 作者:行者123 更新时间:2023-12-03 01:19:22 27 4
gpt4 key购买 nike

我正在尝试使用 Terraform 在 Azure 上的 Linux VM 上安装 Jira Service Management。 Jira 的安装似乎工作正常,我现在正在尝试将 Jira 的证书附加到 Java key 存储。

我遇到的问题是当我启动虚拟机时,我似乎无法运行任何 sudo 命令。当我输入“sudo”时,出现此错误:

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

我尝试编辑 sudoers 文件,但编辑器打开空白并显示我没有权限。我读过,我需要尝试运行“pkexec nano/etc/sudoers”,但随后它提示我输入 root 密码以作为 super 用户运行。我使用 Terraform 创建了虚拟机,但从未设置过密码,因此我不知道 root 密码是什么。我无法运行 visudo,因为它返回“visudo:/etc/sudoers:权限被拒绝”。

我可以做什么来获得 sudo 权限?在配置 VM 时,Azure 中是否需要执行某些操作,或者 Terraform 代码中是否存在可能影响 sudo 权限和功能的位置?

最佳答案

您遇到的错误是相同的问题,您可以尝试以下可能适合您的建议。

<强>1。重命名当前文件

 mv /etc/sudoers{,.bak}

<强>2。创建一个新的vi/etc/sudoers,其基本内容如下:

    /etc/sudoers                                                                              # 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:/snap/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
rahul ALL=(ALL) NOPASSWD: /usr/bin/dockerd

enter image description here

3 .运行 visudo 并添加您的自定义内容。

您还可以尝试不同的 troubleshooting如果上述不起作用,请解决。

关于linux -/etc/sudoers 文件有问题但无法访问 root,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72369505/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com