Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a EC2 instance running. How can I run commands with sudo through Jenkins? When I try sudo touch /home/ec2-user/foo.bar, 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/foo.bar without having to enter a password. –  Andrew M. Feb 14 '12 at 16:56
1  
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

1 Answer 1

up vote 6 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

Your Answer

 
discard

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.