I’m using Ubuntu 14.04. I have edited my /etc/sudoers file to look like so

Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
%deployers ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

And I have added one of my system users to the “deployers” group …

rails@mymachine:~$ whoami
rails@mymachine:~$ groups
rails deployers

However, when I run my script as the user above, using the “sudo” command, I’m getting a “sudo: no tty present and no askpass program specified” error. Here is the script in question …

. ~/.bash_profile
echo "$PATH" 

while read oldrev newrev ref
    if [[ $ref =~ .*/master$ ]];
        echo "Master ref received.  Deploying master branch to production..."
        mkdir -p $WORK_TREE
        git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
        mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log

        # start deploy tasks
        cd $WORK_TREE
        sudo bundle install

and here’s the output …

remote: /usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/rvm/rubies/ruby-2.3.0/bin
remote: rails
remote: Master ref received.  Deploying master branch to production...
remote: sudo: no tty present and no askpass program specified

How do I prevent this message and execute the command properly?

  • This could help – TheOdd Nov 4 '16 at 20:14
  • This line in my file -- %deployers ALL=(ALL) ALL" doesn't already do that? – Dave Nov 4 '16 at 20:25
  • You didn't specify NOPASSWD, so sudo still needs a mechanism (TTY or askpass program) to obtain the invoking user's password. – steeldriver Nov 4 '16 at 23:26

Browse other questions tagged or ask your own question.