本文翻譯自: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 poweroff
, start
和 stop
而無需提示輸入密碼。 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:
嘗試:- Use
line for all commands, I mean: 對所有指令使用NOPASSWD
行,我的意思是:NOPASSWD
- Put the line after all other lines in the
file. 将行放在sudoers
檔案中的所有其他行之後。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 do
each do
expect "[sudo] password for _your_username_:" do
send _your_password_
end
end
end
[this uses one of the alternatives to Expect TCL extension: ruby_expect gem].
[這使用了Expect TCL擴充的替代方法之一: ruby_expect gem]。