Capistrano 3 Wordpress deployment with cap staging deploy on bitbucket fails

I am trying to do a Capistrano 3 deploy for my Wordpress setup as per this screencast
I am deploying to an ubuntu 12.04 server

So here is my deploy.rb file:

set :application, 'dladv'
set :repo_url, ''

set :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

set :deploy_via, :copy
set :deploy_to, '/var/www/php/domain' # I have set the correct permissions with www:data group and added stager as member of this group

set :log_level, :debug
set :pty, true

set :linked_dirs, %w{uploads}

# set :default_env, {}

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app) do
      sudo "apache2ctl", "graceful", "-v"


And my staging.rb looks like this:

set :stage, :staging

server '', user: 'stager', roles: %w{web app db}, port: 47

# set it globally
set :ssh_options, {
 keys: %w(/home/stager/.ssh/id_rsa),
 forward_agent: true,
 auth_methods: %w(password)

Now when I try to do cap staging deploy --trace, I get:

→ cap staging deploy --trace
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
** Invoke deploy (first_time)
** Execute deploy
** Invoke deploy:starting (first_time)
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
 INFO [217d8451] Running /usr/bin/env mkdir -p /tmp/dladv/ on
DEBUG [217d8451] Command: /usr/bin/env mkdir -p /tmp/dladv/
cap aborted!
Authentication failed for user
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh.rb:217:in `start'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/connection_pool.rb:25:in `create_or_reuse_connection'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:173:in `ssh'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:126:in `block in _execute'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `tap'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `_execute'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/tasks/git.rake:13:in `block (3 levels) in <top (required)>'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/amiterandole/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
  1. I have added my imac’s ssh/ key to the server’s authorized_keys file and
  2. I have generated ssh-keygen -t rsa -C "" on the server and then added that key to both my github account and my bitbucket account

I don’t know why it keeps saying Authentication failed for user
Please help

If you’re just connecting with an SSH key you should only need this:

set :ssh_options, {
 keys: %w(/home/stager/.ssh/id_rsa)

You were specifying auth_methods password as well which is different.

1 Like

Ok first it turns out I was using server keys instead of my home computer’s keys. So I fixed that and I got things going. Meanwhile, qhat should I use instead of auth_methods?

Just having

set :ssh_options, {
 keys: %w(/home/stager/.ssh/id_rsa)

is enough if you want to use a key. No auth_methods needed. The following should work without prompting for a password: ssh if that doesn’t work then Capistrano can’t connect either.

Thank you for that clarification. May I also ask:

You have a restart task in your tutorial which doesn’t work for me without being sudo:

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app) do
      sudo "apachectl", "restart", "-v


Capistrano 3 doesn’t allow sudo and my whole deploy crashes. What can I do about this?

If that’s your exact code, you’re missing a closing " at the end. So that’s just a Ruby syntax error. Cap 3 does have sudo: