I have one build machine which has a user abc which is has limited sudo access. When I check out the source code and run my build script, it works fine. The build script contains sudo calls for which it does not say "sudo: no tty present and no askpass program specified". But when I did same thing with Jenkins on a build machine added as slave, it shows "sudo: no tty present and no askpass program specified".

I have found one solution saying to comment out Default requiretty in the file /etc/sudoers. But I don’t have access to this file.

How I can overcome this problem?

  • Is this command you're trying to run via sudo allowed to run without entering a password? If you have to enter a password, sudo is going to require a tty. – Patrick Oct 13 '14 at 13:09
  • Yes ..it runs without entering a password – Niraj Oct 14 '14 at 4:58

There are two options, comment out the Defaults requiretty setting from /etc/sudoers as you mentioned or use the pseudo-tty allocation (-t) argument for ssh.

Try the following in your jenkins script:

ssh -t 127.0.0.1 "sudo command"

Although you will have to have ssh pre-shared keys configured to yourself and run it once manually to add an entry to known hosts, alternatively add the -o StrictHostKeyChecking=no argument to ssh to ignore this.

It fails, because sudo is trying to prompt on root password and there is no pseudo-tty allocated.

You've to either log-in as root or set-up the following rules in your /etc/sudoers (or: sudo visudo):

# Members of the admin group may gain root privileges.
%admin  ALL=(ALL) NOPASSWD:ALL

Then make sure that your Jenkins user belongs to admin group (or wheel).

Ideally (safer) it would be to limit root privileges only to specific commands which can be specified as %admin ALL=(ALL) NOPASSWD:/path/to/program

If you are executing commands via ssh, you need to check the "Exec in pty" option. enter image description here

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.