Problems using GIT w/ SSH key file under Windows - windows

I've problems using GIT with the shell, Visual Studio Code and Visual Studio 2015 (community edition).
Earlier this year I started using GIT with eGit (under Eclipse of course) without any problems. I installed GIT on my server, created a ssh key pair and after a few tests it worked (and still works).
However, now I want to use that GIT on my server with Visual Studio Code and maybe later with Visual Studio 2015.
I got stuck on this issue: GIT trys to use my PPK and asks me for the passphrase (which is emtpy). If I enter a wrong phrase it asks again and continues only if I answer correct (simply enter key). So I think everything is OK till here. But then it asks for the user password for the git-user (the right one btw) on the server and fails. Why?
In the log of my server I can't see any entry about logging in using the key file, only the errors about trying to log in with the password (which is disabled).
If I use putty with that key file I'm able to connect to my GIT server and I also get an entry in the log file. So I'm sure that everything is OK with the server.
What am I missing? I would appreciate any help about that!
Using it with Visual Studio 2015 (I can't solve the issue that it doesn't find libssh when I try to recompile the GIT module following the well known blog entry from Bernardo Pastorelli) or saving the enter key press would be a bonus, however, I would be happy if I could use GIT with key file under Shell / Visual Studio Code at all.
OS: Windows 7 64 bit
GIT 2.10.2.windows.1
VSC: V 1.7.2
TIA!

I'll try to answer the simpler question in your Post:
I would be happy if I could use GIT with key file under Shell
Once, that is done, you can build on it.
Git for windows uses Openssh and therefore will not be able to use the putty PPK file directly.
Two ways forward
Option 1: Convert PPK file to OpenSSH format
Steps to do so:
Open your private key in PuTTYGen
Top menu “Conversions”->”Export OpenSSH key”.
Save the new OpenSSH key when prompted.
To use this new openssh key for your git server, do the following:
Open up Git Bash shell and there edit ~/.ssh/config (create ~/.ssh/ if it does not exist) and define this host:
Host AuxBurgerGitServer
Hostname whatevers-your-git-remote-is
User the-git-user
IdentityFile ~/.ssh/the-open-ssh-key-exported-before
Test this by doing a ssh -T AuxBurgerGitServer which should not show any errors.
If you go this way, you should use the HOST defined above whenever referring to any repositories on this host. Therefore, for example, to clone a repo you would do something like:
git clone ssh://AuxBurgerGitServer/some-repo-name
Option 2: Configure your GIT to use pageant
You can load your PPK file in pageant and configure GIT to use pageant for authentication.
For this, the only thing you would need is to setup an environment variable like so using:
Control Panel → System → Advanced system settings → Environment variables
(or on Windows 10: Control Panel → Search → Environment variables)
GIT_SSH=c:\Program Files\Putty\plink.exe

Related

On Windows 10 that is well configured with native OpenSSH's ssh-agent, how to have an implementation of git use the ssh-agent configured?

I have configured Native Windows 10 OpenSSH like described here: https://www.makeuseof.com/tag/windows-10-ssh-vs-putty/
Also I have started as a service ssh-agent, added private key, and between restart my private key password's are remembered.
So mainly, I can do the following immediately after a restart without a prompt: ssh -T git#gitlab.com
However, I don't know how to get any implementation of 'git' to delegate the ssh work to the Windows native ssh-agent, so that I can execute without any prompt a clone like: git clone git#gitlab.com:SandboxAtHoopSoft/create-aws-accounts.git
Solutions found are:
Set OS environment variable:
set GIT_SSH=C:\WINDOWS\System32\OpenSSH\ssh.exe
OR
Set git config:
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
Just solved this myself this was a very frustrating journey but for me the following got me going:
Make sure C:\Windows\System32\OpenSSH\ is in your path variables (yea I know Windows should see this on its own)
Go to C:\Users\<your user>\.gitconfig edit your global git config file to point to the correct ssh.exe: C:/Windows/System32/OpenSSH
Make sure your id_rsa.ppk file is in C:\Users\<your user>\.ssh If you don't have an SSH key yet generate one and make sure it ends up in this folder
You may also want to check that your OpenSSH Authentication Agent is started in Windows Services

IntelliJ IDEA git Permission denied (publickey)

I got a strange problem with using git on IntelliJ IDEA on Windows 10.
If I want to access the remote repo on GitLab, I always get
Permission denied (publickey).
Everything I found here or via Google didn't solve the problem.
I tried:
Setting the ssh executable to Native
Converting my public key from Putty to ssh-keygen style
Removing known_hosts
I also tried to access the repo with Git Bash, it works fine like that.
Another interesting fact is that after removing known_hosts, I got "Host key verification failed". I had to use Git Bash once to recreate the known_hosts entry, after that I got the Permission denied error again. Somehow I don't get asked for any user input.
I faced this problem while connecting bitbucket cloud from my Intellij 2019.2 , which thankfully got solved with the following steps. Please note that these steps are to be carried out after you successfully generate and add ssh-public key to your bitbucket/github/gitlab profile.
Open Git-SCM ssh_config file present in Git-SCM installation directory.It's default location in Windows (for 64 bit) is in C:\Program Files\Git\etc\ssh\
Add the following lines into ssh_config
Host *your-gitlab-or-github-or-bitbucket-hostname*
IdentityFile *your-ssh-rsa-privatekey-file-with-absolute-path*
for e.g
Host bitbucket.org
IdentityFile C:/Users/Sahil/.ssh/id_rsa
Source:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004124959-IntelliJ-2019-1-3-Can-t-access-git-using-SSH-keys
Update IDEA 2021.2.3
The bug in Sahil's answer has been fixed and Christian's solution is not needed with the correct entry in your ssh config file for the most common case of one key for one or more hosts. Additional options for complex configurations, such as multiple keys to the same or multiple hosts, can be found in Maddes comprehensive answer on superuser.
ANY inconsistency between ssh-agent and ssh-add leads to a situation where some things work and some don't.
For example, I had the Windows OpenSSH agent running but my path pointed first to the Git for Windows ssh-add. Many such failures are possible given the many ssh implementations out there, so know that you know where things are running from.
To get ssh working in IDEA...
Git for Windows
Install Git for Windows. I put it in C:\Git since, as a standard user without an elevated install, I couldn't write to C:\Program Files.
In Control Panel | User Accounts | Change my environment variables add the Git usr\bin folder to the path after the cmd folder entry already there (e.g. C:\Git\usr\bin for my installation).
Unset environment variable HOME -- it still breaks ssh in this version of IDEA.
In a Windows cmd.exe console, run start-ssh-agent.cmd to start the agent
In IDEA in Settings | SSH Configurations | Authentication type: set it to Key pair OpenSSH or PuTTY and test your connection. Then, make a small change and test Commit and push....
Windows OpenSSH
In Control Panel | User Accounts | Change my environment variables add C:\Windows\System32\OpenSSH to your path. Make sure no other ssh implementation is ahead of this in the path!
Start the OpenSSH agent in Task Manager | Services (or any number of other ways)
Set your IDEA SSH Configuration as #5 above
Keep in mind that, on Windows, ssh in IDEA uses the environment available in a standard Windows command-line console (cmd.exe). If git operations work there, then with the above steps in place, they'll work in IntelliJ.
It has been really long since OP but here is my solution on an execution basis:
You need to open a prompt and set the ENVVAR GIT_SSH_COMMAND.
You need to open IntelliJ from that same prompt.
Example:
> set GIT_SSH_COMMAND=ssh -i C:\\path\\to\\not\\default\\key
> idea
Also the path to not-default-key should use ~ instead of %userprofile% or paths unix-like using /.
I was having this same issue, and while it did have to do with the public key, my issue was concerned with WSL2/Linux and windows .ssh folders. My keys were in my WSL2/linux folder system, but intelliJ was looking in my windows folder system.
I copied my rsa keys from WSL2 to windows, and it worked automatically. In fact, I attempted to have it fail again by removing the keys from the Windows folders, but intelliJ must have it's own keylocker solution, because even without the keys in the Windows .ssh folder intelliJ continued to work.
For a screen capture explaining it you can see it here https://vimeo.com/558267383/74d55415c4
If you're using wsl2 in Clion like me, just add
Host github.com
IdentityFile /home/yieatn/.ssh/github
to /home/user/.ssh/config (create if it doesn't exit). You don't even have to restart IDE.
Adding to Cristian Torres's answer:
For all of you folks struggling with a similar problem on Mac OSX:
In IntelliJ, PyCharm, etc. click Tools -> Create Command-line Launcher...
Open your terminal and execute:
$ export GIT_SSH_COMMAND="ssh -i ~/.ssh/your-custom-private-key"
$ idea
For PyCharm the executable name is charm or /usr/local/bin/charm
Goland: goland or /usr/local/bin/goland
WebStorm: webstorm or /usr/local/bin/webstorm

SourceTree + OpenSSH error: Could not open a connection to your authentication agent

I've been trying to add a private key for a while now using SourceTree and OpenSSH. I have tried all the solutions and derivations proposed in this answer to no avail. I've tried all variations of
eval `ssh-agent -s`
ssh-add
that I've found. I disabled all firewalls, antivirus, and even tried it in netorked safe mode. The first command runs fine, and the agent gets a pid, but the ssh-add command throws the error in the title every time. I've also used different names for the .pem file, including the original name and location, username/.ssh/id_rsa.pem (some people had had problems due to the file name), etc., but nothing changes.
I can connect manually to the repository by using the command
ssh -i /route/to/key/key_name.pem ubuntu#serverip
but I want to be able to use it to push changes to the repo through Git. I'm really stumped on this one, and I'm by no means an expert. Can anyone think of another reason for this?
In the end I had to give up on using OpenSSH for Windows. I installed PuTTY, transformed the .pem key into a .ppk with PuTTYgen, and added the private key with SourceTree without trouble.

Source Tree for Windows doesn't seem to work with valid SSH key

I have created an ssh key pair using putty within Source Tree on Windows, and then added that to my repo client (I use Gitlab on a personal server).
This works fine from gitbash (cloning and pushing etc) and via SourceTree for OSX but after adding the .ppk key to pageant, which is actively running and seems to have loaded the key correctly, I cannot seem to clone via SourceTree. I get a "This is not a valid source Path/URL" when adding the repo path with details stating:
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and repository exists.
If I add an existing repo that I have cloned using the same ssh key pair via git bash (by just drag dropping the folder into Source Tree for Windows) that seems to work up to a point - I can commit and see history etc. When I try to Push, however, it fails with much the same message (I've altered the repo path):
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v
--tags origin master:master Pushing to git#MyServer.com:MyRepo.git
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and the repository exists.
Completed with errors, see above.
As far as I can tell Pageant is up and running with the correct (well only) ssh key on my machine.
Any help is very welcomed.
Ok so this is a little embarrasing/confusing.
It would seem that I did not copy the correct public key onto my repo management web interface. The thing is, I copied the public key from git bash using the command:
clip < ~/.ssh/id_rsa.pub
But that seems to give me a different public key from what I actually get opening id_rsa.pub in a text editor...
Is that normal? Why is it different? Why does it work within gitbash and not in SourceTree (via pageant).
Anyway, copying the contents of my public key in directly from the file when opened in notepad got things to work with SourceTree and Pageant etc.

SVN+SSH and Sourceforge

I'm new to both Sourceforge and SVN (SilkSVN on Windows).
I managed to check out a project using
svn co --username=zeroth123 svn://zeroth123#svn.code.sf.net/p/stddecimal/code/trunk stddecimal-code
However, every time I try and use ssh (so I can check in for example) it fails with
> svn co --username=zeroth123 svn+ssh://zeroth123#svn.code.sf.net/p/stddecimal/code/trunk stddecimal-code
svn: E720087: Unable to connect to a repository at URL 'svn+ssh://zeroth123#svn.code.sf.net/p/stddecimal/code/trunk'
svn: E720087: Can't create tunnel: The parameter is incorrect.
I've set SVN_SSH to point to my fully qualified plink.exe and it makes no difference. I also tried changing it to junk.exe and didn't get anything different, so I don't think we're even looking at SVN_SSH, which exhausts all of the advice I've been able to find on the Sourceforge and other forums.
For the record I am the project administrator and therefore have write permissions (or at least think I do!)
Any ideas?
`%SVN_SSH% needs to be set correctly and an SSH key needs to be registered with Sourceforge.
Note that new Sourceforge projects are version 2.0 by default, while 99% of the Sourceforge documentation is for version 1.0 and appears outdated.
These instructions assume you have SVN and the PuTTY tools installed, and that you can successfully access your project using a non-secure protocol, eg the read-only svn checkout svn://USER#svn.code.sf.net/p/PROJECT/code/trunk PROJECT-code style command should work.
These instructions explain how to do the same with svn checkout svn+ssh://... which is needed for write access to Sourceforge.
Set %SVN_SSH% to the fully qualified path of your SSH client. E.g. setx SVN_SSH "C:/Program Files (x86)/PuTTY/plink.exe"
svn expects forward slashes or double back-slashes in the path
You may have to reopen a cmd window
Test by typing %SVN_SSH% at the prompt and confirm you get your ssh programs help screen (or whatever behaviour you expect from executing with no arguments)
(Optional?) Cache the server RSA key. Open PuTTY, login to svn.code.sf.net (or whatever the server of your project is). A prompt will appear asking if you if you want to cache the server RSA key - click Yes.
You might not need to do this, if not when you use SVN to connect ot your project for the first time you will be asked the same question. Type y.
However, I did this because I thought the interactive prompt could be part of the problem.
Create a public / private key and register the public key with Sourceforge.
On creating a key, more info herefor example.
If you use PuTTY, use PuTTYgen to create the key, and make sure the private key is loaded in pageant. Ironically Launchpad has excellent instructions.
The public key can be registered on Sourceforge by navigating to Home > Account > Services and clicking Edit SSH Keys for Shell/CVS.
Now a checkout using svn+ssh protocol should work!
I followed the instructions here and it worked. Its a quicker method that doesn't require uploading keys etc.
Download plink.exe from http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe
Place the plink.exe in your windows installation directory (%windir%)
Open the following file using Notepad %APPDATA%\Subversion\config
Add or Replace the following line in the [tunnels] section (replace login and pwd with your sourceforge login and password)
ssh = c:\\windows\\plink.exe -batch -l <LOGIN> -pw <PWD>
(note the double backslash)
Save and close the file
For me the issue was that Tortoise was initially installed on the D drive. I uninstalled it and reinstalled it on C without changing the related settings. The solution was to copy the TortoiseSVN folder from C drive to its original location in D drive.
For anybody (like me) working with Tortoise SVN who has it working for Tortoise SVN but needs command line access for easier bulk analysis... and doesn't want to go through the faff of registering an SSH key.
Copy the value you are using in Tortoise - Settings - Network - SSH Client (mine has username, password arguments)
Edit the command line configs ssh line in %APPDATA%\Subversion\config as per the answer above to use the line you copied from Tortoise
That way, you can use the Tortoise Plink.exe with arguments for username and password.

Resources