Push Upstream with EGit and Eclipse Indigo

While working through the EGit User Guide I ran into difficulty pushing files upstream using Eclipse Indigo SR1 (build 20110916-0149). The difficulties manifested themselves at first with an “auth failed” error, which was quickly resolved with a visit to Stack Overflow. But after fixing that problem I began seeing the following error while trying to push to a remote repo:

Cannot get remote repository refs.
Reason:
ssh://git@github.com:22: Passphrase for C:\Users\...\.ssh\id_rsa

Initial research indicated that Eclipse/EGit SSH authentication has problems. So I just kept messing around until I was able to get things working. After a little Googling and even more fiddling I found two solutions:

Simple fix that skips the passphrase and uses only Eclipse

  1. Use ssh-keygen from Git Bash, or Eclipse, to generate an RSA key, but do so without setting a passphrase.
  2. Open and copy the public key from ~/.ssh/id_rsa.pub and add it to GitHub via the SSH Public Keys section in Account Settings.
  3. Restart Eclipse. (Note: Not doing this was tripping me up for a while.)
  4. Try the Push Upstream steps again from the EGit User Guide.

The obvious pitfall here is that a passphrase cannot be associated with the RSA key. If skipping the passphrase is out of the question the following solution a little more up your alley.

Use PuTTY for file transfers over SSH from within Eclipse

  1. Download the following PuTTY binaries: Plink, Pageant and PuTTYgen.
  2. Use PuTTYgen to generate a new public/private key pair with a passphrase. Open and copy the public key from ~/.ssh/id_rsa.pub and add it to GitHub via the SSH Public Keys section in Account Settings. Save the private key file in your ~/.ssh directory for later.
  3. Run Pageant and add the key created during the last step, entering the passhprase when prompted. Leave this utility running.
  4. Cache the server’s host key in the registry by:
    1. From a bash prompt like Git Bash execute the following command (assumes Plink binary is accessible from the current path): plink git@github.com
    2. Verify the RSA key fingerprint matches GitHub’s and, if they match, choose to store the key in the registry.
  5. Add a new environment variable called GIT_SSH and point it to the downloaded Plink binary (e.g. “C:\Windows\system32\plink.exe”). EGit will attempt to use this binary for SSH, if configured.
  6. Restart Eclipse, ensuring Pageant is still running with the private key available.
  7. Try the Push Upstream steps again from the EGit User Guide.

If done correctly, Eclipse should allow pushes to the remote repo without any further configuration, though Pageant must be running with the private key configured for it to work correctly. If problems continue see the SSH issues in the GitHub help documentation for additional information. Good luck!

  • Hery Ratsimihah

    Thanks, I’ve been struggling with it for the whole evening. Your post is the only one that provides a solution that works, and besides it’s nicely presented. :) (I missed the restart step as well)

  • http://www.habdas.org/ Josh Habdas

    Thanks. Glad it helped. Happy coding.

  • Sorin Popa

    Hello, amigos!
    I hope this helps…

    1. Download the latest version of JSch jar (currently 0.1.45) from the creator’s site: http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.45/jsch-0.1.45.jar/download2. Rename it so it has the same name as the JSch plugin jar from your Eclipse Indigo.3. Add the eclipse specific files to the newly renamed jar, by copying the originals from the one in Indigo.4. Replace the jar in Indigo with this one.Now, authentication goes well to git, passphrase is successfully accepted.
    If you’ve set your passphrase to none/empty/etc.. please set it back to something right. Otherwise, using these keys is really as good as using none.

    I wish you all the best!

  • http://www.habdas.org/ Josh Habdas

    Thanks for the help, Sorin. I followed the instructions and replaced the com.jcraft.jsch_0.1.41.v201101211617.jar with the modified jsch-0.1.45.jar. After generating a new RSA key with passphrase and restarting Eclipse the same “Cannot get remote repository refs” transport issue continues to occur. I also tried the remote push using both RSA and DSA key types but it didn’t seem to make a difference. Any other suggestions?

  • Anonymous

    Thanks Josh, this works like a charm, works much better than the StackOverflow solution, maybe you should put it back there and i can +1 u up :)

  • http://www.habdas.org/ Josh Habdas

    Glad to hear it worked out well. Please consider linking off to my site from StackOverflow and taking the credit for finding this resource, if you felt it was valuable and may be useful to others.

  • http://twitter.com/caravaggisto William C Grisaitis

    Thanks a ton for the solution, Josh! The first method works well for me. But, being morally opposed to empty passwords, I have since discovered a more secure, and just as elegant, solution (not that using PuTTY is not elegant…). At the “Push” window, select the http protocol (not ssh), and in the username / password fields at the bottom, replace git / *empty* with your github username / password combination.

    If I do this, everything works fine. I don’t have to deal with any SSH passwords. Now, if you’re behind some heavy duty firewall, this may not work. But it should work for most. :)

    Thanks to Josh, though, for providing the clear and useful tips!

  • http://www.habdas.org/ Josh Habdas

    Thanks. Glad you were able to find another method. I’m sure it’ll come in handy.

  • http://www.manakor.org Nikita Sumeiko

    Your simple fix that skips passphrase helped me very much. Now pushing to upstream is working in Eclipse like a charm. Thanks a lot, very useful.

  • http://www.manakor.org Nikita Sumeiko

    Your simple fix that skips passphrase helped me very much. Now pushing to upstream is working in Eclipse like a charm. Thanks a lot, very useful.