1

I"m using packer to create automated linux golden images.

When I try and run a script that requires sudo, I get the following error

sudo: no tty present and no askpass program specified

This error has been discussed at length on the internet, the recommended advice is use one of the following:

  1. ssh using -t
  2. Remove from /etc/sudoers Defaults:username !requiretty
  3. export SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass
  4. Add user to suoders group %admin ALL=(ALL) NOPASSWD:ALL

I've verified that the /etc/sudoers file that ships with ubuntu 16.04 does not contain requiretty. Why does ubuntu still give error sudo: no tty present and no askpass program specified

enter image description here

https://github.com/mitchellh/vagrant/issues/1482

https://askubuntu.com/questions/281742/sudo-no-tty-present-and-no-askpass-program-specified

closed as off-topic by Jeff Schaller, Eric Renouf, Stephen Harris, GAD3R, mdpc Sep 14 '16 at 1:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Eric Renouf, Stephen Harris, GAD3R, mdpc
If this question can be reworded to fit the rules in the help center, please edit the question.

1

Turns out it was a problem with the order of scripts.

Once I allowed the vagrant user sudo rights inside the sudoers file, the problem went away.

https://github.com/chef/bento/blob/master/scripts/ubuntu/sudoers.sh

sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=sudo' /etc/sudoers
sed -i -e 's/%sudo  ALL=(ALL:ALL) ALL/%sudo  ALL=NOPASSWD:ALL/g' /etc/sudoers

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