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

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

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

sudo: no tty present and no askpass program specified

第一次执行sudo命令时。

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

还有其他解决办法吗?


当前回答

如果你碰巧来这里是因为你不能在Windows10自带的Ubuntu中sudo

在Windows中编辑/etc/hosts文件(使用记事本),它将位于:%localappdata\lxss\rootfs\etc,添加127.0.0.1 WINDOWS8,这将消除无法找到主机的第一个错误。 要消除no tty present错误,请始终执行sudo -S <命令>

其他回答

1 打开 /etc/sudoers

输入sudo vi /etc/sudoers.这将以编辑模式打开您的文件。

2添加/修改linux用户

查找Linux用户的条目。如果找到,则按以下方式修改或添加新行。

<USERNAME> ALL=(ALL) NOPASSWD: ALL

3保存并退出编辑模式

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

我在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

这是所有。

我希望这对你们有帮助

允许用户使用该命令而不提示输入密码应该可以解决这个问题。首先打开一个shell控制台,输入:

sudo visudo

然后编辑该文件添加到最后:

username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand

eg

john ALL = NOPASSWD: /sbin/poweroff, /sbin/start, /sbin/stop

将允许用户约翰sudo关机,启动和停止没有提示密码。

查看屏幕底部你需要在visudo中使用的击键——顺便说一下,这不是vi——并在出现任何问题的第一个迹象时不保存就退出。健康警告:损坏此文件将导致严重后果,请小心编辑!

Try:

ssh -t remotehost "sudo <cmd>"

这将消除上述错误。