Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano "No tty present and no askpass program specified"

I'm running cap production deploy and I keep getting the following error sudo: no tty present and no askpass program specified after /usr/bin/env sudo mkdir -pv /home/[user]/apps/[app name] as [user@myIP]

I'm not sure how to fix this.

Capfile:

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
require 'capistrano/passenger'
require 'capistrano/safe_deploy_to'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

any ideas?

like image 977
Marcus Avatar asked Jun 23 '15 22:06

Marcus


2 Answers

One solution would be to allow the sudo command on your server without entering a password, but that could be a security risk.

Alternatively, you can fix your Capistrano configuration because something is likely wrong. It would help if you showed us the contents of your deploy.rb file but first thing I would do is ensure that you have default_run_options[:pty] set to true in deploy.rb. Or add the line if you're missing it.

Capistrano 2

default_run_options[:pty] = true

Capistrano 3

set :pty, true
like image 89
Mike S Avatar answered Sep 27 '22 21:09

Mike S


On server open visudo file for editing:

sudo visudo

and list all commands that your deployment user is allowed to run without entering password, eg.:

deploy_user        ALL=(ALL) NOPASSWD: \
  /bin/systemctl status puma_production, \
  /bin/systemctl start puma_production, \
  /bin/systemctl stop puma_production, \
  /bin/systemctl restart puma_production

save the file and try to run capistrano command again. You could allow all commands by NOPASSWD:ALL but it's considered not safe ofc as for unprivileged user.

Note: ensure your executable path is full – eg. not systemctl but /bin/systemctl, which you can get by which systemctl command

like image 22
Lev Lukomsky Avatar answered Sep 27 '22 22:09

Lev Lukomsky