I am trying to compile some sources using a makefile. In the makefile there is a bunch of commands that need to be ran as 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. Once I type in the password, make resumes and completes.
But I would like to be able to compile the sources in NetBeans. So, I started a project and showed netbeans where to find the sources, but when I compile the project it gives the error:
sudo: no tty present and no askpass program specified
The first time it hits a sudo
command.
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. I do not want to do that.
Is there any other solution?
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. In this case, you can use Expect utility (http://en.wikipedia.org/wiki/Expect) or its alternatives.For example, in Ruby to execute
sudo ls
without gettingsudo: no tty present and no askpass program specified
, you can run this:[this uses one of the alternatives to Expect TCL extension: ruby_expect gem].
Make sure the command you're
sudo
ing is part of yourPATH
.If you have a single (or multi, but not ALL) command
sudoers
entry, you'll get thesudo: no tty present and no askpass program specified
when the command is not part of your path (and the full path is not specified).You can fix it by either adding the command to your
PATH
or invoking it with an absolute path, i.e.sudo /usr/sbin/ipset
Instead of
sudo ipset
Maybe the question is unclear that why no answer was matching it but I had the same error message when I was trying to mount sshfs which required sudo : the command is something like this :
by adding the option
-o debug
I had the same message of this question :
So by reading others answer I became to make a file in
/etc/sudoer.d/user
on my.server.tld with :and now I able to mount the drive without giving too much extra right to my user.
Try:
This will remove the above errors.
sudo
by default will read the password from the attached terminal. Your problem is that there is no terminal attached when it is run from the netbeans console. So you have to use an alternative way to enter the password: that is called the askpass program.The askpass program is not a particular program, but any program that can ask for a password. For example in my system
x11-ssh-askpass
works fine.In order to do that you have to specify what program to use, either with the environment variable
SUDO_ASKPASS
or in thesudo.conf
file (seeman sudo
for details).You can force
sudo
to use the askpass program by using the option-A
. By default it will use it only if there is not an attached terminal.For Ubuntu 16.04 users
There is a file you have to read with:
Placing a file with mode 0440 in /etc/sudoers.d/myuser with following content:
Should fix the issue.
Do not forget to: