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

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

其他回答

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

虽然这个问题很老了,但它仍然与我的最新系统相关。在启用sudo的调试模式(调试sudo /var/log/sudo_debug all@info in /etc/sudo.conf)后,我被指向/dev: "/dev is world writable"。因此,您可能需要检查tty文件的权限,特别是tty/pts节点所在目录的权限。

我不确定这是否是最近的更改,但我刚刚遇到了这个问题,sudo -S为我工作。

当我试图挂载sshfs时,我有同样的错误消息,需要sudo:命令是这样的:

sshfs -o sftp_server="/usr/bin/sudo /usr/lib/openssh/sftp-server" user@my.server.tld:/var/www /mnt/sshfs/www

通过添加选项-o debug

sshfs -o debug -o sftp_server="/usr/bin/sudo /usr/lib/openssh/sftp-server" user@my.server.tld:/var/www /mnt/sshfs/www

对于这个问题,我也有同样的意思:

sudo: no tty present and no askpass program specified

所以通过阅读其他人的答案,我开始在/etc/sudoer中创建一个文件D /user在my.server.tld

user ALL=NOPASSWD: /usr/lib/openssh/sftp-server

现在我可以挂载驱动器,而不给我的用户太多额外的权利。

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

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