我正在尝试使用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

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

其他回答

确保你正在执行的命令是你的PATH的一部分。

如果您有一个(或多个,但不是ALL)命令sudoers条目,当命令不是路径的一部分(并且没有指定完整路径)时,您将得到sudo: no tty present和没有指定askpass程序。

您可以通过将命令添加到PATH或使用绝对路径调用它来修复它。

sudo /usr/sbin/ipset

而不是

须藤ipset

其他选项,不基于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.

运行包含来自jenkins的sudo命令的shell脚本可能无法按预期运行。要解决这个问题,请遵循以下步骤

简单的步骤:

在基于ubuntu的系统中,运行" $ sudo visudo " 这将打开/etc/sudoers文件。 如果jenkins用户已经在该文件中,那么修改如下:

詹金斯

保存文件 重新开始你的jenkins工作 你不应该再看到错误信息:)

默认情况下,Sudo将从连接的终端读取密码。您的问题是,从netbeans控制台运行时没有附加终端。因此,您必须使用另一种方法来输入密码:即所谓的askpass程序。

askpass程序不是一个特定的程序,而是任何可以要求密码的程序。例如,在我的系统中,x11-ssh-askpass工作正常。

为了做到这一点,你必须指定要使用的程序,可以使用环境变量SUDO_ASKPASS,也可以在sudo.conf文件中指定(详情请参阅man sudo)。

您可以使用选项-A强制sudo使用askpass程序。默认情况下,它只在没有附加终端时使用它。

命令sudo失败,因为它试图提示输入root密码,并且没有分配伪tty(因为它是脚本的一部分)。

您需要以root身份登录运行此命令,或者在/etc/sudoers中设置以下规则 (或:sudo visudo):

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

然后确保您的用户属于admin组(或wheel)。

理想情况下(更安全),将根权限限制为只允许指定为%admin ALL=(ALL) NOPASSWD:/path/to/program的特定命令