Skip to main content

Fixing SSH connection problems in EGit in Eclipse


Note: I posted a version of this on Stack Overflow.
Errors can occur when there is an underlying SSH authentication issue, like having the wrong public key on the git remote server or if the git remote server changed its SSH host key.
Often the an SSH error will appear as: "Invalid remote: origin: Invalid remote: origin"

Eclipse will use the .ssh directory you specify in Preferences -> General -> Network Connections -> SSH2 for its ssh configuration. Set it "{your default user directory}.ssh\" .
To fix things, first you need to determine which ssh client you are using for Git. This is stored in the GIT_SSH environmental variable. Right-click on "Computer" (Windows 7), then choose Properties -> Advanced System Settings -> Environment Variables.
If GIT_SSH contains a path to plink.exe, you are using the PuTTY stack.
  • To get your public key, open PuTTYgen.exe and then load your private key file (*.ppk). The listed public key should match the public key on the git remote server.
  • To get the new host key, open a new PuTTY.exe session, and then connect to git@{git repo host}.
  • Click OK and say yes to store the new key.
  • Once you get a login prompt, you can close the PuTTY window. The new key has been stored.
  • Restart Eclipse.
If GIT_SSH contains a path to "ssh.exe" in your "Git for Windows" tree, you are using Git for Windows's OpenSSH.
  • Set %HOME% to your default user directory (as listed in Eclipse; see above).
  • Set %HOMEDRIVE% to the drive letter of your default user directory.
  • Set %HOMEPATH% to the path to your default user directory on %HOMEDRIVE%
  • To get your public key, open the file %HOMEDRIVE%%HOMEPATH%/.ssh/id_rsa.pub (or id_dsa.pub) in a text editor. The listed public key should match the public key on the git remote server.
  • To get the new host key, run: cmd.exe
  • Run Git Bash
  • Ctrl-C
  • At the bash prompt, run /c/path/to/git/for/windows/bin/ssh.exe git@{git remote host}.
  • Type yes to accept the new key.
  • Once you have a login prompt, type: ctrl-c
  • Close the cmd.exe window
  • Restart Eclipse.
Finally, if you are still having trouble with your external ssh client, delete the GIT_SSH environmental variable and set the HOME environmental variable to your default user directory on Windows. Without the GIT_SSH variable, EGit will use its internal ssh client (java). It will use the .ssh directory you specified above as its SSH configuration directory.
Note: If you have Git for Windows, you can use its tools to create a SSH key pair your .ssh directory:
  • Set %HOME% to your default user directory (as listed in Eclipse).
  • Set %HOMEDRIVE% to the drive letter of your default user directory.
  • Set %HOMEPATH% to the path to your default user directory on %HOMEDRIVE%
  • Run Git Bash
  • Ctrl -C
  • Run: ssh-keygen.exe -t rsa -b 2048
  • Save to the default filenames
  • Choose a passphrase or save without one. If you save with a passphrase, Eclipse will prompt you for it each time you push or pull from your git remote server.
  • Close Git Bash
You can also use the GUI in the SSH2 Preference pane in Eclipse to manage hosts and keys.

Comments

Popular posts from this blog

PowerShell One-Liners

Introduction PowerShell is Microsoft's shell for their product lines. It's now on version 3.0. If you miss the power of the command line while using Windows on either your laptop or servers, PowerShell provides that power. Important concepts: Almost all aspects of the Microsoft ecosystem are objects within an overarching structure. You query and manipulate this structure and its objects with PowerShell. This includes all aspects of SharePoint, Active Directory, and Exchange. Other companies, like VMware (see below) have also written PowerShell modules. This "object nature" means that PowerShell pipes pass objects and properties, not just text.  Variables store data-structures of objects.  One-liners Note: Unwrap the code lines before you use them. Get Help Get the usage of the command "Select-Object": Get-Help Select-Object Built-in examples for the command "Select-Object": Get-Help Select-Object -exam

How the find the Active Directory Domain Controllers listed in DNS on Linux...

Assumptions: You have the "host" utility from BIND. You can do a zone transfer from the local DNS server Your Active Directory admins have properly configured DNS for Active Directory If you have the above, use the following command: host -t srv -l your.active.directory.dns.domain | grep _kerberos._tcp.*._sites.dc._msdcs.your.active.directory.dns.domain Replace your.active.directory.dns.domain with your actual AD DNS domain.