Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a EC2 instance running. How can I run commands with sudo through Jenkins? When I try sudo touch /home/ec2-user/, I get the following error: sudo: no tty present and no askpass program specified.

What am I doing wrong?

share|improve this question
A complete guess (I know nothing about Jenkins) - check for Defaults requiretty in sudoers (using visudo) and comment it out (probably bad security practise though, but it might help narrow down your problem). – cyberx86 Feb 14 '12 at 16:04
@cyberex86 I should have mentioned I already did that, that's why I get the error above. Having requiretty yields sudo: sorry, you must have a tty to run sudo. – whirlwin Feb 14 '12 at 16:16
Does your user have NOPASSWD set (I believe that is the default for Amazon's Linux AMI) and did you set visiblepw? – cyberx86 Feb 14 '12 at 16:34
To bank off @cyberx86, you should be able to run (on the Jenkins box) as sudo -u jenkins touch /home/ec2-user/ without having to enter a password. – Andrew M. Feb 14 '12 at 16:56
Thanks the both of you! I used the solution by @cyberx86 (I'll accept if you post an answer), in addition I had to create the user jenkins. – whirlwin Feb 14 '12 at 21:18
up vote 8 down vote accepted

By default sudo cannot be used without a TTY. In order to do so:

  • Disable 'requiretty' in sudoers (using visudo)
    • This should amount to commenting out 'Defaults requiretty' (using visudo)

  • Ensure that your user is able to login without entering a password:
    • Set 'NOPASSWD' in sudoers
    • Create the user if the user does not exist

  • Set visiblepw - this will allow sudo to work, even if the password entered is displayed
    • (required in some cases when echo cannot be disabled).
share|improve this answer
What do you mean by using visudo? – Dejel Nov 27 '14 at 11:29
@Odelya: visudo is the program used to edit the sudoers file. It is similar to vi(m), however, it performs some checks to catch invalid entries. – cyberx86 Nov 27 '14 at 21:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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