title: Capistrano 3 deploy fails connecting to GitHub - Permission denied (publickey)
body: <p>I have the following deploy script set up with Capistrano v3 and capistrano/symfony gem. I am deploying to an AWS EC2 instance with Ubuntu 14.4
  I am connecting with a .pem file downloaded from AWS. I have the following in my deploy.rb</p>
  
  <pre><code>set :pty, true
  
  set :ssh_options, {
    user: 'ubuntu',
    keys: ['/Users/myuser/Sites/Myproject.pem'],
    forward_agent: true,
    auth_methods: ["publickey"]
  }
  </code></pre>
  
  <p>when deploying with</p>
  
  <pre><code>bundle exec cap staging deploy --trace
  </code></pre>
  
  <p>The script connects fine but fails on this</p>
  
  <pre><code>INFO [4fd1b02c] Running /usr/bin/env git ls-remote --heads git@github.com:MyName/Myproject.git as ubuntu@ec2-00-000-000-000.eu-west-1.compute.amazonaws.com
  DEBUG [4fd1b02c] Command: ( SYMFONY_ENV=prod GIT_ASKPASS=/bin/echo GIT_SSH=/var/www/tmp/myproject/git-ssh.sh /usr/bin/env git ls-remote --heads git@github.com:MyName/Myproject.git )
  
  DEBUG [4fd1b02c]    Permission denied (publickey).
  DEBUG [4fd1b02c]    
  DEBUG [4fd1b02c]    fatal: Could not read from remote repository.
  DEBUG [4fd1b02c]    
  DEBUG [4fd1b02c]    
  DEBUG [4fd1b02c]    Please make sure you have the correct access rights
  DEBUG [4fd1b02c]    
  DEBUG [4fd1b02c]    and the repository exists.
  DEBUG [4fd1b02c] 
  
  cap aborted!
  SSHKit::Runner::ExecuteError: Exception while executing as ubuntu@ec2-00-000-000-000.eu-west-1.compute.amazonaws.com: git exit status: 128
  git stdout: Permission denied (publickey).
  fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  git stderr: Nothing written
  </code></pre>
  
  <p>I don't know why forward_agent is not working?</p>
  
  <p>I have been trying to follow this guide - <a href="https://developer.github.com/guides/using-ssh-agent-forwarding/#testing-ssh-agent-forwarding" rel="nofollow">https://developer.github.com/guides/using-ssh-agent-forwarding/#testing-ssh-agent-forwarding</a></p>
  
  <p>but when I get to this</p>
  
  <pre><code>echo "$SSH_AUTH_SOCK"
  </code></pre>
  
  <p>It prints a blank line.</p>
  
  <p>Also if I run this on the server it says command not found</p>
  
  <pre><code>sshd_config
  </code></pre>