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

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!

Leave a Comment