title: Capistrano and several SSH keys
body: <p>I need Capistrano to use 2 different SSH keys. One is for the git repository, one is for the server to deploy to.</p>
  
  <p>Whichever key I rename to id_rsa in my .ssh folder, works. The other one doesn't. If I rename the git key to id_rsa, Capistrano can connect to the git repository, but then can't authenticate at the server to deploy. If I call it something else, it will not be able to connect to the git repo. I know that the other key works, cause I can do ssh -i ~/.ssh/otherKey.pem and it will successfully connect to the server.</p>
  
  <p>This is what I have in my deploy.rb Capistrano file.</p>
  
  <pre><code>ssh_options[:keys] = [
          File.join(ENV["HOME"], ".ssh", "id_rsa"),
          File.join(ENV["HOME"], ".ssh", "deploy")
      ]
  
  ssh_options[:forward_agent] = true 
  </code></pre>
  
  <p>How can I tell Capistrano to use BOTH the keys? It only seems to use the one called id_rsa.</p>
  
  <p>edit:</p>
  
  <p>Here's the output from Capistrano with the error message:</p>
  
  <pre><code>$ cap yii deploy
    * executing `yii'
  Yii
    * executing `deploy'
    * executing `deploy:update'
   ** transaction: start
    * executing `deploy:update_code'
      executing locally: "git ls-remote git@project.beanstalkapp.com:/projectyii.git HEAD"
    * executing "git clone -q git@project.beanstalkapp.com:/projectyii.git /var/www/projectyii-trunk/releases/20110824174629 &amp;&amp; cd /var/www/projectyii-trunk/releases/20110824174629 &amp;&amp; git checkout -q -b deploy 5e14521285ca04a605353e97bdf31c3a2889dbfb &amp;&amp; (echo 5e14521285ca04a605353e97bdf31c3a2889dbfb &gt; /var/www/projectyii-trunk/releases/20110824174629/REVISION)"
      servers: ["yii.project.com"]
      [yii.project.com] executing command
   ** [yii.project.com :: err] Error reading response length from authentication socket.
   ** [yii.project.com :: err] Permission denied (publickey,keyboard-interactive).
   ** [yii.project.com :: err] fatal: The remote end hung up unexpectedly
      command finished
  *** [deploy:update_code] rolling back
    * executing "rm -rf /var/www/projectyii-trunk/releases/20110824174629; true"
      servers: ["yii.project.com"]
      [yii.project.com] executing command
      command finished
  failed: "sh -c \"git clone -q git@project.beanstalkapp.com:/projectyii.git /var/www/projectyii-trunk/releases/20110824174629 &amp;&amp; cd /var/www/projectyii-trunk/releases/20110824174629 &amp;&amp; git checkout -q -b deploy 5e14521285ca04a605353e97bdf31c3a2889dbfb &amp;&amp; (echo 5e14521285ca04a605353e97bdf31c3a2889dbfb &gt; /var/www/projectyii-trunk/releases/20110824174629/REVISION)\"" on yii.project.com
  </code></pre>
  
  <p>edit:</p>
  
  <p>Another thing: it totally works fine from my local machine, just not on the deploy server - with exactly the same config files! It seems Capistrano uses the correct keys on my local machine, but not on the deploy machine.</p>