Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitExtensions + Putty via SSH on custom port

I have a Git repository that I pull using a path similar to this:

git pull ssh://[email protected]:1234/path/to/repository.git

When GitExtensions then tries to pull from the repository using plink, it makes this call:

plink -T [email protected]:/path/to/repository.git

This ends up failing because it's actually pinging port #22, and not #1234.

The right call to make would be

plink -T -P 1234 [email protected]:/path/to/repository.git

If I create an alias "hostCom" in my ~/.ssh/config, it seems to work correctly (connecting to #1234) if I just do this:

plink -T username@hostCom

But as soon as I add the path to the Git repository too, it goes to #22 again.

Another option I tried is to create a session in PuTTY. Let's call it "hostPutty", and set the default port there, etc. The bottom line ends up being the same though: Can't combine path to Git repository with a custom port.

How do I combine all the parts to make them work?

And how come OpenSSH can deal with the problem, but PuTTY can't? The only problem with OpenSSH is that it keeps asking me for the password for the private key on every connection attempt (and I don't want to create a private key without a password).

like image 330
mac Avatar asked Sep 06 '12 12:09

mac


2 Answers

I got it figured out.

Here's what got me down the wrong path:

  • Do not create any sessions in PuTTY as outlined here
  • Do not use any host aliases you might have defined in file ~/.ssh/config

Here's how you get it working:

  • Obviously make sure GitExtensions is set to use PuTTY, not OpenSSH
  • Make sure plink.exe (the one available with GitExtensions or specifically installed with PuTTY) is in a path without spaces
  • Set your environment variable %GIT_SSH% to point to plink.exe (it might be pointing to ssh.exe by default), make sure there aren’t apostrophes since the value will be used "as-is" (that's why you can't use spaces as stated above)
echo %GIT_SSH%

C:\tools\PuTTY\plink.exe
  • Use the "full" command to pull, without any host aliases that would allow you to not specify the port, etc., in the example above. If the port is missing, and there's just a colon, Git treats it as a path separator, and ssh as the port delimiter (so they bite each fairly bad).

    git clone ssh://[email protected]:1234/path/to/repository.git

If you do that, Git and plink actually figure things out right!

If you don't do it this way, you might run into all kinds of problems like:

  • I had %GIT_SSH% pointed to ssh.exe and used a host alias instead of path incl. the port

ssh.exe": hostPutty:path: no address associated with name
fatal: The remote end hung up unexpectedly

  • Used apostrophes in %GIT_SSH%

error: cannot spawn "C:\tools\PuTTY\plink.exe": No such file or directory
fatal: unable to fork

like image 159
mac Avatar answered Oct 18 '22 19:10

mac


For me, I kept getting an error that host name did not exist. After trying a bunch of suggestions on this and other threads, I checked my remote URL and that was the culprit. If you are using PuTTY, make sure it starts with [email protected], not https://github.

Here's an example of how to check this in Git extensions

like image 1
BraveNewMath Avatar answered Oct 18 '22 18:10

BraveNewMath