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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With