Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'sudo: no tty present and no askpass program specified' error?

Tags:

linux

sudo

tty

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?

like image 240
hebbo Avatar asked Feb 09 '14 13:02

hebbo


People also ask

What is an Askpass helper?

If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard output. If the SUDO_ASKPASS environment variable is set, it specifies the path to the helper program. Otherwise, if sudo.

How do I get to Sudoers file?

However, your username must be in the sudoers file. You can find the sudoers file in “/etc/sudoers”. Use the “ls -l /etc/” command to get a list of everything in the directory. Using -l after ls will give you a long and detailed listing.

What is sudo option?

“Sudo” is short for Superuser Do. With this command, any user who has been granted permissions has access to root-like privileges without having to actually be a superuser.

What is SUDO_ASKPASS?

Basically the value of $SUDO_ASKPASS is to be an executable that will spit your password to standard out when invoked. So, if your password was 'foo', you could write a shell script as: #!/bin/bash echo 'foo' and place it in ~/bin/pw.sh .


1 Answers

Granting the user to use that command without prompting for password should resolve the problem. First open a shell console and type:

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.

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. Health warning: corrupting this file will have serious consequences, edit with care!

like image 171
nicdaniau Avatar answered Sep 30 '22 12:09

nicdaniau