title: Capistrano from rc.local ssh authentication failed
body: <p>I'm setting simple capistrano 3 deployment script to run from rc.local for each of new nodes that get spawned by aws autoscaler.</p>
  
  <p>Everything runs just fine when I execute the script manually as root, but once I reboot and look at rc.local execution log I get following:</p>
  
  <pre><code>cap aborted!
  SSHKit::Runner::ExecuteError: Exception while executing on host 127.0.0.1: Authentication failed for user ubuntu@127.0.0.1
  /var/lib/gems/1.9.1/gems/net-ssh-2.9.1/lib/net/ssh.rb:219:in `start'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
  /var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in &lt;top (required)&gt;'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
  Net::SSH::AuthenticationFailed: Authentication failed for user ubuntu@127.0.0.1
  /var/lib/gems/1.9.1/gems/net-ssh-2.9.1/lib/net/ssh.rb:219:in `start'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
  /var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in &lt;top (required)&gt;'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
  /var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
  Tasks: TOP =&gt; git:check =&gt; git:wrapper
  (See full trace by running task with --trace)
  The deploy has failed with an error: #&lt;SSHKit::Runner::ExecuteError: Exception while executing on host 127.0.0.1: Authentication failed for user ubuntu@127.0.0.1&gt;
  </code></pre>
  
  <p>To avoid known_hosts problems root user has ~/.ssh/config</p>
  
  <pre><code>Host 127.0.0.1
      StrictHostKeyChecking no
      UserKnownHostsFile=/dev/null
  </code></pre>
  
  <p>As root user </p>
  
  <pre><code>ssh ubuntu@127.0.0.1 
  </code></pre>
  
  <p>goes just fine.</p>
  
  <p>rc.local looks like this:</p>
  
  <pre><code>#!/bin/bash -ex
  #
  # rc.local
  #
  # This script is executed at the end of each multiuser runlevel.
  # Make sure that the script will "exit 0" on success or any other
  # value on error.
  #
  # In order to enable or disable this script just change the execution
  # bits.
  #
  # By default this script does nothing.
  
  exec &gt; &gt;(tee /var/log/rc.local.log|logger -t rc.local -s 2&gt;/dev/console) 2&gt;&amp;1
  
  /home/ubuntu/deployment/local-deploy.sh
  
  exit 0
  </code></pre>
  
  <p>As said running /home/ubuntu/deployment/local-deploy.sh as root user manually works just fine but when it is run on boot (from rc.local) I get authentication error above.</p>
  
  <p>Thanks for any help.</p>