本文翻译自:How to fix 'sudo: no tty present and no askpass program specified' error?

I am trying to compile some sources using a makefile. 我正在尝试使用makefile编译一些源。 In the makefile there is a bunch of commands that need to be ran as sudo . 在makefile中,有一堆需要作为sudo运行的sudo

When I compile the sources from a terminal all goes fine and the make is paused the first time a sudo command is ran waiting for password. 当我从终端编译源代码时,一切正常,第一次运行sudo命令等待密码时,make暂停。 Once I type in the password, make resumes and completes. 输入密码后,make即可恢复并完成操作。

But I would like to be able to compile the sources in NetBeans. 但是我希望能够在NetBeans中编译源代码。 So, I started a project and showed netbeans where to find the sources, but when I compile the project it gives the error: 因此,我启动了一个项目,并向netbeans展示了在哪里可以找到源代码,但是当我编译该项目时会出现错误:

sudo: no tty present and no askpass program specified

The first time it hits a sudo command. 第一次命中sudo命令。

I have looked up the issue on the internet and all the solutions I found point to one thing: disabling the password for this user. 我在互联网上查找了该问题,发现的所有解决方案都指向一件事:禁用该用户的密码。 Since the user in question here is root. 由于此处讨论的用户是root。 I do not want to do that. 我不想那样做。

Is there any other solution? 还有其他解决方案吗?


#1楼

参考:https://stackoom.com/question/1Ssez/如何修复-sudo-不存在tty且未指定AskPass程序-错误


#2楼

sudo by default will read the password from the attached terminal. 默认情况下, sudo将从连接的终端读取密码。 Your problem is that there is no terminal attached when it is run from the netbeans console. 您的问题是从netbeans控制台运行时没有连接终端。 So you have to use an alternative way to enter the password: that is called the askpass program. 因此,您必须使用另一种方式输入密码:称为AskPass程序。

The askpass program is not a particular program, but any program that can ask for a password. askpass程序不是特定程序,而是可以要求输入密码的任何程序。 For example in my system x11-ssh-askpass works fine. 例如,在我的系统中, x11-ssh-askpass可以正常工作。

In order to do that you have to specify what program to use, either with the environment variable SUDO_ASKPASS or in the sudo.conf file (see man sudo for details). 为此,您必须使用环境变量SUDO_ASKPASS或在sudo.conf文件中指定要使用的程序(有关详细信息,请参见man sudo )。

You can force sudo to use the askpass program by using the option -A . 您可以通过使用-A选项强制sudo使用askpass程序。 By default it will use it only if there is not an attached terminal. 默认情况下,仅当没有连接的终端时,它才会使用它。


#3楼

Try: 尝试:

ssh -t remotehost "sudo <cmd>"

This will remove the above errors. 这将消除上述错误。


#4楼

Granting the user to use that command without prompting for password should resolve the problem. 授予用户使用该命令而不提示输入密码的权限,应该可以解决该问题。 First open a shell console and type: 首先打开一个shell控制台并输入:

sudo visudo

Then edit that file to add to the very end: 然后编辑该文件以添加到最后:

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

eg 例如

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

will allow user john to sudo poweroff , start and stop without being prompted for password. 将允许用户john sudo poweroffstartstop而无需提示输入密码。

Look at the bottom of the screen for the keystrokes you need to use in visudo - this is not vi by the way - and exit without saving at the first sign of any problem. 在屏幕底部查看需要在visudo中使用的击键-顺便说一句,这不是vi-并退出而不保存任何问题的第一个迹象。 Health warning: corrupting this file will have serious consequences, edit with care! 健康警告:损坏此文件将有严重后果,请谨慎编辑!


#5楼

Try: 尝试:

  1. Use NOPASSWD line for all commands, I mean: 对所有命令使用NOPASSWD行,我的意思是:

     jenkins ALL=(ALL) NOPASSWD: ALL 
  2. Put the line after all other lines in the sudoers file. 将行放在sudoers文件中的所有其他行之后。

That worked for me (Ubuntu 14.04). 这对我有用(Ubuntu 14.04)。


#6楼

This error may also arise when you are trying to run a terminal command (that requires root password) from some non-shell script, eg sudo ls (in backticks) from a Ruby program. 当您尝试从某些非Shell脚本运行终端命令(需要root密码)时,例如在Ruby程序中的sudo ls (在反引号中),也会出现此错误。 In this case, you can use Expect utility ( http://en.wikipedia.org/wiki/Expect ) or its alternatives. 在这种情况下,您可以使用Expect实用程序( http://en.wikipedia.org/wiki/Expect )或其替代方法。
For example, in Ruby to execute sudo ls without getting sudo: no tty present and no askpass program specified , you can run this: 例如,在Ruby中执行sudo ls而不获取sudo: no tty present and no askpass program specified ,您可以运行以下命令:

require 'ruby_expect'exp = RubyExpect::Expect.spawn('sudo ls', :debug => true)
exp.procedure doeach doexpect "[sudo] password for _your_username_:" dosend _your_password_endend
end

[this uses one of the alternatives to Expect TCL extension: ruby_expect gem]. [这使用了Expect TCL扩展的替代方法之一: ruby_expect gem]。

如何修复“ sudo:不存在tty且未指定AskPass程序”错误?相关推荐

  1. 【Linux】普通用户修改 root 权限文件,没有权限;sudo: 没有终端存在,且未指定 askpass 程序

    文章目录 现象 报错信息: 解决问题: 方法一: 方法二: 方法三: 现象 在php 使用 ssh2_connect 执行 echo 'rootpwd' | sudo sh -c 'echo -e & ...

  2. java 打开指定文件,java解决指定应用程序打开指定文件

    java解决指定应用程序打开指定文件 //打开工具的路径及名字 String toolsPath = "D:/office/Office12/WINWORD.EXE"; //被打开 ...

  3. linux 设置更新源为cd,技术|如何修复 apt-get update 无法添加新的 CD-ROM 的错误

    这些天我正在体验Elementary OS Freya,在这期间,我遇到了一个非常常见的更新错误:Failed to fetch cdrom Please use apt-cdrom to make ...

  4. 如何修复ubuntu中检测到系统程序错误的问题

    作者:Abhishek来源:Linux中国 在过去的几个星期,(几乎)每次都有消息 Ubuntu 15.04在启动时检测到系统程序错误 跑出来"欢迎"我.那时我是直接忽略掉它的,但 ...

  5. 如何在计算机配置里面设置隐藏c盘,玩转电脑组策略(指定运行程序/隐藏C盘)

    在实际生活中我们往往遇到这样或那样的小问题,比如看看谁最近谁用了我电脑.运行了些什么软件.抑或是不想让特定的用户随便安装软件.难道解决这些问题只能依靠相关的优化软件么?答案是肯定的,在这里我就不得提到 ...

  6. pycharm执行python程序报错ImportError: DLL load failed: torchvision找不到指定的程序

    ImportError: DLL load failed: 找不到指定的程序 参考 https://blog.csdn.net/shuiyixin/article/details/90370588 C ...

  7. 在任意的远程桌面的session中运行指定的程序

    //在其它session中(如远程桌面的session)运行指定的程序,需要具有system权限,可以在任意的桌面里运行指定程序#include <windows.h> #include ...

  8. 成功解决mod = importlib.util.module_from_spec(spec)ImportError: DLL load failed: 找不到指定的程序。

    成功解决mod = importlib.util.module_from_spec(spec)ImportError: DLL load failed: 找不到指定的程序. 目录 解决问题 解决思路 ...

  9. 成功解决Exception unhandled ImportError DLL load failed: 找不到指定的程序。 lib\imp.py, Line: 343

    成功解决Exception "unhandled ImportError" DLL load failed: 找不到指定的程序. lib\imp.py, Line: 343 目录 ...

最新文章

  1. Oracle总结第二篇【视图、索引、事务、用户权限、批量操作】
  2. 新版微信对付款码截屏做处理 防止被骗
  3. STM32开发 -- CAN总线详解
  4. [洪流学堂]Hololens修改图标icon
  5. zz Oracle存储过程总结
  6. ==、Equals 、ReferenceEquals它们的异同
  7. JMJS系统总结系列----XSLT的语句规则(一)
  8. 型机器人同人本子_唯美的人×机器人漫画《純情愛玩生化女友》
  9. android中pdf转换成图片格式,Android-PDF转图片
  10. 2005年10月--至今 开发过的项目
  11. python作图设置背景颜色_如何在matplotlib中设置绘图的外部背景颜色
  12. .Net Task常见问题
  13. 0018 求球的表面积和体积
  14. 纯电动汽车两档ATM变速箱simulink模型,模型实现了两档AMT换挡策略和换挡过程仿真
  15. 罗克韦尔自动化2018年自动化博览会开始接受注册
  16. 大一寒假培训(二)——快排与桶排
  17. Android短彩信数据库解析
  18. 经验分享:使用Python3处理excel-案例1
  19. win7计算机右边预览,Win7系统资源管理器加上预览窗格功能的方法
  20. 有没有那么一瞬间,你也曾有过“失业焦虑”?

热门文章

  1. OpenGL学习总结
  2. c++一日一练:让标准的输入输出流关联一个缓冲区
  3. Ubentu编译Android源码(AOSP)
  4. 如何让项目一步步走向灭亡
  5. Android性能优化典范第四季
  6. MySQL学习随笔记录
  7. Django生命周期
  8. Repeater控件使用小结持续更新
  9. VS生成时复制文件到指定目录
  10. percentiles of live data capture