Capistrano SSH authentication failure

capistrano

After moving a Capistrano build server from one machine to another, I noticed some failures during the first build. This might’ve been an environmental issue, but instead of going for the easy option I preferred to modify this directly in the Capfile.

My error message received was:
connection failed for: some-linux-server01 (Net::SSH::AuthenticationFailed: www-data)

I tried a host of options, adjusting the SSH config, /etc/hosts, and specifying ssh_options[:forward_agent] = true in the Capfile. Nothing worked.

First thing I wanted to do, was setup some more verbose Capistrano logging:
ssh_options[:verbose] = :debug

Then try and running a cap deploy again. That information may shed some light on any issue you have. In my case, it appeared to be a recurring issue with my SSH config – as we’d upgraded both Ruby, Capistrano and the OS – I preferred for the job to be done in the Capfile instead.

Subsequently, I planned to setup the Capfile to locate my SSH keys directly, whilst ignoring config.

The solution:
ssh_options[:keys] = [File.join(ENV[“HOME”], “.ssh”, “id_rsa”)]
ssh_options[:config] = false

…added to the Capfile, commit and then attempt another deploy.