title: Github SSH config containing multiple ssh keys capistrano deployment fails saying Repository not found
body: <p><strong>~/.ssh/config</strong></p>
  
  <pre><code># User_A
  Host github.com-User_A
  HostName github.com
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa
  IdentitiesOnly yes
  
  # User_B
  Host github.com-User_B
  HostName github.com
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa_user_b
  IdentitiesOnly yes
  
  # http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods
  Host example.com
  IdentityFile ~/.ssh_keys/example_env.pem
  ForwardAgent yes
  </code></pre>
  
  <p>On local machine:</p>
  
  <pre><code>  $ ssh -T git@github.com
    Hi User_B! You've successfully authenticated, but GitHub does not provide shell access.
  </code></pre>
  
  <p>On remote machine</p>
  
  <pre><code>    ~$ ssh remote_user@example.com
  
      [remote_user@example ~]$ ssh -T git@github.com
      Hi User_A! You've successfully authenticated, but GitHub does not provide shell access.
  </code></pre>
  
  <p>Note: </p>
  
  <ul>
  <li>ssh-add -l shows all the mentioned keys enlisted</li>
  <li><p>deploy.rb contains: </p>
  
  <pre><code> set :repository,  "git@User_B:&lt;REPO_NAME&gt;"
  
   ssh_options[:forward_agent] = true
  </code></pre></li>
  </ul>
  
  <p>I am trying to deploy my application using Capistrano to an Amazon EC2 instance for which I the .pem file is already added to my local machine using ssh-add and it can be seen enlisted in output for <em>ssh-add -l</em>.However I am facing following error while deploying:</p>
  
  <pre><code>** [example.com :: err] ERROR: Repository not found.
  ** fatal: The remote end hung up unexpectedly
  </code></pre>
  
  <p>Following is the full output of my cap deploy command:</p>
  
  <pre><code>$ cap bat deploy
  
    triggering load callbacks
  * executing `bat'
    triggering start callbacks for `deploy'
  * executing `multistage:ensure'
  * executing `deploy'
  * executing `deploy:update'
     ** transaction: start
  * executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@User_B:&lt;REPO_NAME&gt; &lt;BRANCH_NAME&gt;"
    command finished in 6296ms
  * executing "if [ -d /srv/&lt;APP_NAME&gt;/shared/cached-copy ]; then cd /srv/&lt;APP_NAME&gt;/shared/cached-copy &amp;&amp; git fetch -q origin &amp;&amp; git fetch --tags -q origin &amp;&amp; git reset -q --hard df84fadff305e1729991caddde47f6802e424d57 &amp;&amp; git clean -q -d -x -f; else git clone -q git@User_B:&lt;REPO_NAME&gt; /srv/&lt;APP_NAME&gt;/shared/cached-copy &amp;&amp; cd /srv/&lt;APP_NAME&gt;/shared/cached-copy &amp;&amp; git checkout -q -b deploy df84fadff305e1729991caddde47f6802e424d57; fi"
    servers: ["example.com"]
    [example.com] executing command
     ** [example.com :: err] ERROR: Repository not found.
     ** fatal: The remote end hung up unexpectedly
    command finished in 3811ms
    *** [deploy:update_code] rolling back
  * executing "rm -rf /srv/&lt;APP_NAME&gt;/releases/20130723222237; true"
    servers: ["example.com"]
    [example.com] executing command
    command finished in 477ms
    failed: "sh -c 'if [ -d /srv/&lt;APP_NAME&gt;/shared/cached-copy ]; then cd /srv/&lt;APP_NAME&gt;/shared/cached-copy &amp;&amp; git fetch -q origin &amp;&amp; git fetch --tags -q origin &amp;&amp; git reset -q --hard df84fadff305e1729991caddde47f6802e424d57 &amp;&amp; git clean -q -d -x -f; else git clone -q git@User_B:&lt;REPO_NAME&gt; /srv/&lt;APP_NAME&gt;/shared/cached-copy &amp;&amp; cd /srv/&lt;APP_NAME&gt;/shared/cached-copy &amp;&amp; git checkout -q -b deploy df84fadff305e1729991caddde47f6802e424d57; fi'" on example.com
  </code></pre>
  
  <p>So I guess this error is caused due to conflicts arising between multiple SSH keys getting detected i.e. on local machine User_B(who is a member of the repository) is used as default however on remote machine User_A(who is not having access to the repository) is used.</p>
  
  <p>If my assumption is correct can anybody please help me in getting this problem solved? Is there any way in which a specific user config can be used while agent forwarding? If not then what could be the solution to this?</p>
  
  <p>Thanks.</p>