Luna Paglarelli Luna Paglarelli - 1 year ago 111
Git Question

Can't ssh to remote repository from command line

I'm trying to connect to a remote repository under a specific IP address.

I received the private key through email and I'm on windows using Putty. The .ppk file is in Pageant.

I also created a GIT_SSH environment variable.

After these steps my personal IP was then listed in the firewall, so I guess I was able to connect.

However, when I use git bash to connect to the server, I get the message "permission denied (public key)".

The commands I used are:

$ ssh [IP]
$ ssh [username]@IP
$ ssh -T [username]@IP

I looked up online exhaustively but with no success so far and I really need to access the repo as soon as possible.

Thanks in advance!
Obrigada :)

Answer Source

Two ways to go about it

Using Pageant directly inside Git Bash

This requires setting the GIT_SSH environment variable to the full path of plink.exe (which is part of the putty suite).

Also, I would highly recommend checking if plink.exe works inside GIT Bash as follows:

Full-path-to-plink.exe -v -P port sshusername@sshserver

Another thing to check is the version of Putty suite that you are using. ( I can dig out the details later but) version 0.60 had a bug due to which processes inside cmd could not access Pageant. I believe the issue was fixed in v 0.62 but feel free to use the latest (v 0.67)

Convert putty key to OpenSSH format

Another possibility is exporting the putty key to the OpenSSH format by using puttygen.exe and the using the exported key directly inside GIT Bash:

  1. Open PuttyGen
  2. Click Load
  3. Load your private key
  4. Go to Conversions->Export OpenSSH and export your private key
  5. Copy your private key to ~/.ssh/id_dsa (or id_rsa).
  6. Create the RFC 4716 version of the public key using ssh-keygen

    ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/
  7. Convert the RFC 4716 version of the public key to the OpenSSH format:

    ssh-keygen -i -f ~/.ssh/ > ~/.ssh/

Then you can do something like this in GIT Bash to test the ssh connectivity:

ssh -v sshusername@sshserver -i ~/.ssh/id_rsa
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download