title: Connect to private github repository with libgit2
body: <p>I'm trying to fetch a private github repository using libgit2. The repo belongs to an organization and I have read/write permissions. The program is written in Objective-C++. I have this:</p>
  
  <pre><code>- (int)fetchBranches
  {
      git_remote *remote = NULL;
      int result = 0;
      if (!(result = git_remote_load(&amp;remote, repo, "origin"))) {
          git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
          callbacks.credentials = cred_acquire_cb;
          git_remote_set_callbacks(remote, &amp;callbacks);
          result = git_remote_fetch(remote);
      }
      return result;
  }
  
  int cred_acquire_cb(git_cred **out,
                      const char * url,
                      const char * username_from_url,
                      unsigned int allowed_types,
                      void * payload)
  {
      return git_cred_ssh_key_new(out, "GITHUBUSERNAME", "/Users/admin/.ssh/id_rsa.pub", "/Users/admin/.ssh/id_rsa", "PASSPHRASE");
  }
  </code></pre>
  
  <p>This creates the credentials but when I do the fetch it fails when trying to authenticate the session with libssh2. (libgit2/src/transports/ssh.c:302):</p>
  
  <pre><code>rc = libssh2_userauth_publickey_fromfile(
        session, c-&gt;username, c-&gt;publickey,
        c-&gt;privatekey, c-&gt;passphrase);
  </code></pre>
  
  <p>The error is -18, LIBSSH2_ERROR_AUTHENTICATION_FAILED. I've confirmed that the public key is added to Github and tried to change it for a new one too. Also the passphrase is correct and the username is my github username. I can do the fetch through the console too. The remote config is:</p>
  
  <pre><code>[remote "origin"]
      url = git@github.com:ORGNAME/REPONAME.git
      fetch = +refs/heads/*:refs/remotes/origin/*
  </code></pre>
  
  <p>I've also tried to get the key from the git-agent in OSX with the same result:</p>
  
  <pre><code>return git_cred_ssh_key_from_agent(out, "GITHUBUSERNAME");
  </code></pre>
  
  <p>Finally I tried using the plaintext authentication:</p>
  
  <pre><code>return git_cred_userpass_plaintext_new(out, username, password);
  </code></pre>
  
  <p>This last method works after changing the repo url to the HTTPS address. The problem is that it requires the user to input the password each time or store the git_cred struct which contains the password in blank (don't like that).</p>
  
  <p>Anyone knows why the ssh authentication is failing? Is there a way to avoid having to input the username/password with each operation (with the plaintext authentication)?</p>