Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices to avoid Jenkins error: sudo: no tty present and no askpass program specified

When running any sudo command from Jenkins I get the following error: sudo: no tty present and no askpass program specified.

I understand that I can solve this by adding a NOPASSWD entry to my /etc/sudoers file which will allow user jenkins to run commands without needing a password. I can add an entry like this:

%jenkins ALL=(ALL)NOPASSWD:/home/me/dir/script.sh 

...but this leads to the following issue: https://stackoverflow.com/questions/17414330/how-to-avoid-specifying-full-path-in-sudoers-file

I can add an entry like this:

%jenkins ALL=NOPASSWD: ALL 

...but this allows user jenkins to avoid the password prompt for ALL commands, which seems a bit unsafe. I'm just curious what my options are here, and if there are any best practices I should consider.

like image 726
s g Avatar asked Jul 01 '13 22:07

s g


People also ask

How do I fix Sudo no tty present and no Askpass specified error?

If you have a single (or multi, but not ALL) command sudoers entry, you'll get the sudo: 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.

What is Askpass in Linux?

Introduction to ssh-askpass The ssh-askpass is a generic executable name for many packages, with similar names, that provide a interactive X service to grab password for packages requiring administrative privileges to be run. It prompts the user with a window box where the necessary password can be inserted.

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.


2 Answers

The no tty thing (requiretty in sudoers) is the real issue.

Basically, comment out the following lines in your /etc/sudoers file:

#Defaults    requiretty #Defaults   !visiblepw 

Other ways to get it to work:

Defaults    !requiretty 

Or per user:

Defaults:jenkins !requiretty 

A more detailed answer is this answer to this question on the Unix & Linux Stack Exchange site:

  • Why does cron silently fail to run sudo stuff in my script? - Unix & Linux Stack Exchange
like image 102
Electrawn Avatar answered Sep 19 '22 13:09

Electrawn


One thing you can do is to get Jenkins to run a script, for example 'run.sh', then from inside this script you can start makefiles, and make sure that there are no sudo commands inside the makefiles.

It is a bit of a hassle, but at least you are not risking changing security settings

like image 35
serup Avatar answered Sep 19 '22 13:09

serup