我正在尝试使用makefile编译一些源代码。在makefile中,有一堆命令需要作为sudo运行。

当我从终端编译源代码时,一切都很好,并且在第一次运行sudo命令等待密码时,make会暂停。一旦我输入密码,做简历和完成。

但是我希望能够在NetBeans中编译源代码。所以,我开始了一个项目,并向netbeans展示了在哪里可以找到源代码,但当我编译项目时,它给出了错误:

sudo: no tty present and no askpass program specified

第一次执行sudo命令时。

我在网上查了这个问题,我找到的所有解决方案都指向一件事:禁用这个用户的密码。因为这里讨论的用户是根用户。我不想那样做。

还有其他解决办法吗?


当前回答

詹金斯:

echo '<your-password>' | sudo -S command

Eg:-

echo '******' | sudo -S service nginx restart

你可以使用掩码密码插件来隐藏你的密码

其他回答

这招对我很管用:

echo "myuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

你的用户是myuser

对于Docker映像,这将是:

RUN echo "myuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

其他选项,不基于NOPASSWD:

Start Netbeans with root privilege ((sudo netbeans) or similar) which will presumably fork the build process with root and thus sudo will automatically succeed. Make the operations you need to do suexec -- make them owned by root, and set mode to 4755. (This will of course let any user on the machine run them.) That way, they don't need sudo at all. Creating virtual hard disk files with bootsectors shouldn't need sudo at all. Files are just files, and bootsectors are just data. Even the virtual machine shouldn't necessarily need root, unless you do advanced device forwarding.

我想我能帮到别人。

首先,我修改了/etc/sudoers中的用户设置,参考上面的答案。但它仍然没有工作。

myuser   ALL=(ALL) NOPASSWD: ALL
%mygroup  ALL=(ALL:ALL) ALL

在我的例子中,myuser在mygroup中。

我不需要小组。删除了这一行。

(不应该像我一样删除这一行,只是标记注释。)

myuser   ALL=(ALL) NOPASSWD: ALL

它的工作原理!

登录到您的linux。执行以下命令。要小心,因为编辑sudoer是一个有风险的命题。

$ sudo visudo

vi编辑器打开后,进行以下更改:

注释掉默认值是必需的 #默认值是必须的 转到文件末尾并添加 NOPASSWD:所有

我在Ubuntu 20.04服务器上工作时遇到了这个问题。

我试图从远程机器运行sudo命令,将应用程序部署到服务器。然而,当我运行这个命令时,我得到了错误:

sudo: no tty present and no askpass program specified
The remote script failed with exit code 1

以下是我的解决方法:

该问题是由执行试图请求密码的sudo命令引起的,但sudo没有访问tty来提示用户输入密码短语。由于无法找到tty, sudo就会退回到askpass方法,但无法找到已配置的askpass命令,因此sudo命令会失败。

要解决这个问题,您需要能够在不要求密码的情况下为特定用户运行sudo。无密码要求在/etc/sudoers文件中配置。要配置它,运行下面的命令:

sudo nano /etc/sudoers

OR

sudo visudo

注意:这将使用默认编辑器打开/etc/sudoers文件。

接下来,在文件底部添加以下一行:

# Allow members to run all commands without a password
my_user ALL=(ALL) NOPASSWD:ALL

注意:将my_user替换为您的实际用户

如果您希望用户运行特定的命令,您可以指定它们

# Allow members to run specific commands without a password
my_user ALL=(ALL) NOPASSWD:/bin/myCommand

OR

# Allow members to run specific commands without a password
my_user ALL=(ALL) NOPASSWD: /bin/myCommand, /bin/myCommand, /bin/myCommand

保存更改并退出文件。

有关更多帮助,请阅读此链接中的资源:sudo: no tty present and no askpass program specified

这是所有。

我希望这对你们有帮助