Git with SSH on Windows - windows

I've went through the excellent guide provided by Tim Davis which is about configuring Git to work with SSH under Windows in order to produce a Git Server in order to have a main place for my DVCS.
I am in the process of creating a clone for my project. I’ve went through all the steps till this point, but I keep getting this from TortoiseGit:
git.exe clone -v “ssh://Administrator#127.0.0.1:22/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
bash: Administrator#127.0.0.1: command not found
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
Success
and nothing gets cloned.
BTW: The TortoisePLink comes up just before this message appears and asks me: “login as:” ( I thought that this info is given in the command, i.e: Administrator#blahblah.
My home variable is set to the correct place:
From a Git Bash shell:
echo $HOME
/c/SSH/home/Administrator
I’ve also tried using Putty’s plink instead of TortoisePLink (in both Git’s and TortoiseGit’s installation). This time the error was narrowed down to:
git.exe clone -v “ssh://Administrator#127.0.0.1:22/c:/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly

I fought with this problem for a few hours before stumbling on the obvious answer. The problem I had was I was using different ssh implementations between when I generated my keys and when I used git.
I used ssh-keygen from the command prompt to generate my keys and but when I tried "git clone ssh://..." I got the same results as you, a prompt for the password and the message "fatal: The remote end hung up unexpectedly".
Determine which ssh windows is using by executing the Windows "where" command.
C:\where ssh
C:\Program Files (x86)\Git\bin\ssh.exe
The second line tells you which exact program will be executed.
Next you need to determine which ssh that git is using. Find this by:
C:\set GIT_SSH
GIT_SSH=C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe
And now you see the problem.
To correct this simply execute:
C:\set GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
To check if changes are applied:
C:\set GIT_SSH
GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
Now git will be able to use the keys that you generated earlier.
This fix is so far only for the current window. To fix it completely you need to change your environment variable.
Open Windows explorer
Right-click Computer and select Properties
Click Advanced System Settings link on the left
Click the Environment Variables... button
In the system variables section select the GIT_SSH variable and press the Edit... button
Update the variable value.
Press OK to close all windows
Now any future command windows you open will have the correct settings.

Since this keeps coming up in search results for making git and github work with SSH on Windows (and because I didn't need anything from the guides above), I'm adding the following, simple solution.
(Microsoft says they are working on adding SSH to Visual Studio, and GitHub for Windows still doesn't support SSH...)
1. I installed "git for Windows" (which includes ssh and a bash shell)
https://git-scm.com/download/win
2. From the included bash shell (which, for me, was installed at: C:\Program Files\Git\git-bash.exe)
cd to the root level of where you want your repo saved (something like: C:\code\github\), and
Type:
eval $(ssh-agent -s) && ssh-add "C:\Users\YOURNAMEHERE\.ssh\github_rsa"
3. Type: (the SSH link from the repo)
git clone git#github.com:RepoName/Project.git

you are using a smart quote “ instead of " here:
git.exe clone -v “ssh://
^^^
Make sure you use the plain-old-double-quote.

I've found my ssh.exe in C:/Program Files/Git/usr/bin directory.

If Git for windows is installed, run Git Bash shell:
bash
You can run ssh from within Bash shell (Bash is aware of the path of ssh)
To know the exact path of ssh, run "where" command in Bash shell:
$ where ssh
you get:
c:\Program Files\Git\usr\bin\ssh.exe

I was trying to solve my issue with some of the answers above and for some reason it didn't work. I did switch to use the git extensions and this are the steps I did follow.
I went to Tools -> Settings -> SSH -> Other ssh client
Set this value to C:\Program Files\Git\usr\bin\ssh.exe
Apply
I guess that this steps are just the same explained above. The only difference is that I used the Git Extensions User Interface instead of the terminal. Hope this help.

When I typed where ssh it showed me multipe ssh.exe
user#pc MINGW64 /c/dev/
$ where ssh
C:\Users\user\AppData\Local\Programs\Git\usr\bin\ssh.exe
C:\Windows\System32\OpenSSH\ssh.exe
Deleting / moving these exe helped:
# copy from
# C:\Users\user\AppData\Local\Programs\Git\usr\bin
# to something like
# C:\Users\user\AppData\Local\Programs\Git\usr\bin\backup-ssh
ssh-agent.exe
ssh.exe
ssh-add.exe
This solved the issue for me.

Related

Maven release:prepare cannot connect to SVN URL [duplicate]

I'm having trouble trying to checkout a repo using the following syntax on a Windows 7 workstation with TortoiseSvn:
svn co svn+ssh://user#ip/repo .
What I've done to test this issue:
Modified the network settings of TortoiseSvn to point to ..\TortoisePlink.exe
Successfully established an ssh connection to the target machine with no issues
Successfully checked out repos from workstations running Ubuntu with OpenSsh
When I try to do the above syntax from the command line on the Windows 7 workstation I get the error:
svn: E720087: Unable to connect to a repository at URL 'svn+ssh:///user#ip/repo'
svn: E720087: Can't create tunnel:The parameter is incorrect.
Interestingly, if I use the tortoise gui to browse to the repo I can successfully open and check out the repo. But I need to do it from the command line for scripting purposes.
Any suggestions?
For svn+ssh to work with Tortoise, make sure %SVN_SSH% is set to your ssh client (probably plink.exe from Tortoise or Putty) and the path must be written either with forward slashes / or with escaped backslashes \\.
Try to set %SVN_SSH% with the absolute path of plink while escaping the backslashes, something like C:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe instead of ..\TortoisePlink.exe
Check that the path to TortoisePlink is not corrupted in your Tortoise SVN config...
Start > Program Files > Tortoise SVN > Settings
Under General Settings, "Subversion configuration file:" click "Edit"
This will open the config file in Notepad
Scroll down to the [tunnels] section and check the value for ssh which should be uncommented, use double slashes etc - I had problems as there seemed to be a Unicode control code at the beginning of the path.
### On Windows, if you are specifying a full path to a command,
### use a forward slash (/) or a paired backslash (\\) as the
### path separator. A single backslash will be treated as an
### escape for the following character.
ssh = C\:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe
Connect to server, using Plink, by hand. Define needed and correct (for you) startup-options of plink
Add this line (use tortoiseplink as windowless-plink) into %APPDATA%config file, [tunnels] section
It also turns out the the line in the Tunnels section of the config file is case sensitive.
For example:
sh = $SVN_SSH "C:/path/putty/plink.exe" -2 -C -i "C:/path/username/serversvn.ppk"
might work
and
sh = $SVN_SSH "C:/path/PuTTY/plink.exe" -2 -C -i "C:/path/username/serversvn.ppk"
won't work
I had a similar, but slightly different issue.
I tried connecting to our SSH+SVN server through Pycharm and it hung. Tried the regular way through windows right click, tortoiseSVN and got this same "Can't create tunnel" issue.
I believe this issue was created because I tried to connect to my repo via pycharm, which automatically created a tunnel line in the tortoise SVN config file.
I followed Kevin Sadler's answer, but just commented out the ssh line, and it was back to normal. Checkouts and commits were working again.
Kevin's answer:
Check that the path to TortoisePlink is not corrupted in your Tortoise SVN config...
Start > Program Files > Tortoise SVN > Settings
Under General Settings, "Subversion configuration file:" click "Edit"
This will open the config file in Notepad
Scroll down to the [tunnels] sections. Comment out the SSH line.

Git on Windows problems

I am running Git on my Windows 8 vm. I have Git bash working no problem with bitbucket. However, I just want to use Command Prompt. I can run git commands from Command Prompt but for some reason it feels like the ssh keys are out of sync, almost if the command prompt is trying to use something other than what bash is using. The error I get when trying to do a simple git pull from command prompt is
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I don't have any issues running the command from git bash. What is even more maddening is that this was working a couple weeks ago. I don't recall doing anything that would have changed this. Maybe a reboot at most. Any ideas?
its possible that the home directory is set differently between Git Bash and Command Prompt. Compare the outputs of the following on both Command Prompt and Git Bash.
ssh -v -T git#github.com
you may need to change your home directory.

Git Hook under Windows

I have the following code to checkout in a working directory in the hook post-receive:
#!/bin/sh
git --work-tree=d:/websites/__gitweb --git-dir=d:/_gitrepo.git/ checkout -f
Unfortunately it doesn't seem to work. However, the command does work when I enter just this in the windows command line (cms):
git --work-tree=d:/websites/__gitweb --git-dir=d:/_gitrepo.git/ checkout -f
I have checked the permissions and the executing attributes but nothing.
UPDATE:
I think I'm getting closer. Now I know what the problem is but I don't know why is this happening. The hook is actually being triggered but I receive this message:
remote: Starting copy from repository to work tree...
remote: fatal: Not a git repository: 'd:/_gitrepo.git/'
remote: Finished.
I have tried to change the path of d: to the whole network path but it still doesn't work. If I go to the remote repository and I do a git log, the changes are there and if I run the hook with sh, it works.
Why is it saying that it is not a git repository when clearly it is?
I finally got it working!
This is really weird. I had to type a pwd to see where actually is the batch being located and it showed the hook location on the server. However, in the next line I added a hostname and it showed me my local hostname.
Then I add the whole path just like:
#!/bin/sh
echo "Starting copy from repository to work tree..."
pwd
hostname
git --work-tree=//remotehost/d$/Webseiten/__gitweb --git-dir=//remotehost/d$/_gitr
epo.git checkout -f
echo "Finished."
I hope this solution works for someone
For a shell script (and those hook scripts will be executed as shell, even in Windows, through the msys layer of msysgit), you could use a different sort of path:
#!/bin/sh
git --work-tree=/d/websites/__gitweb --git-dir=/d/_gitrepo.git/ checkout -f
See also other possibilities with "Posix path conversion in MinGW"

How to use svn+ssh with Tortoise SVN from the command line

I'm having trouble trying to checkout a repo using the following syntax on a Windows 7 workstation with TortoiseSvn:
svn co svn+ssh://user#ip/repo .
What I've done to test this issue:
Modified the network settings of TortoiseSvn to point to ..\TortoisePlink.exe
Successfully established an ssh connection to the target machine with no issues
Successfully checked out repos from workstations running Ubuntu with OpenSsh
When I try to do the above syntax from the command line on the Windows 7 workstation I get the error:
svn: E720087: Unable to connect to a repository at URL 'svn+ssh:///user#ip/repo'
svn: E720087: Can't create tunnel:The parameter is incorrect.
Interestingly, if I use the tortoise gui to browse to the repo I can successfully open and check out the repo. But I need to do it from the command line for scripting purposes.
Any suggestions?
For svn+ssh to work with Tortoise, make sure %SVN_SSH% is set to your ssh client (probably plink.exe from Tortoise or Putty) and the path must be written either with forward slashes / or with escaped backslashes \\.
Try to set %SVN_SSH% with the absolute path of plink while escaping the backslashes, something like C:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe instead of ..\TortoisePlink.exe
Check that the path to TortoisePlink is not corrupted in your Tortoise SVN config...
Start > Program Files > Tortoise SVN > Settings
Under General Settings, "Subversion configuration file:" click "Edit"
This will open the config file in Notepad
Scroll down to the [tunnels] section and check the value for ssh which should be uncommented, use double slashes etc - I had problems as there seemed to be a Unicode control code at the beginning of the path.
### On Windows, if you are specifying a full path to a command,
### use a forward slash (/) or a paired backslash (\\) as the
### path separator. A single backslash will be treated as an
### escape for the following character.
ssh = C\:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe
Connect to server, using Plink, by hand. Define needed and correct (for you) startup-options of plink
Add this line (use tortoiseplink as windowless-plink) into %APPDATA%config file, [tunnels] section
It also turns out the the line in the Tunnels section of the config file is case sensitive.
For example:
sh = $SVN_SSH "C:/path/putty/plink.exe" -2 -C -i "C:/path/username/serversvn.ppk"
might work
and
sh = $SVN_SSH "C:/path/PuTTY/plink.exe" -2 -C -i "C:/path/username/serversvn.ppk"
won't work
I had a similar, but slightly different issue.
I tried connecting to our SSH+SVN server through Pycharm and it hung. Tried the regular way through windows right click, tortoiseSVN and got this same "Can't create tunnel" issue.
I believe this issue was created because I tried to connect to my repo via pycharm, which automatically created a tunnel line in the tortoise SVN config file.
I followed Kevin Sadler's answer, but just commented out the ssh line, and it was back to normal. Checkouts and commits were working again.
Kevin's answer:
Check that the path to TortoisePlink is not corrupted in your Tortoise SVN config...
Start > Program Files > Tortoise SVN > Settings
Under General Settings, "Subversion configuration file:" click "Edit"
This will open the config file in Notepad
Scroll down to the [tunnels] sections. Comment out the SSH line.

'ssh-keygen' is not recognized as an internal or external command

I run git push -u origin master
It tells me that "Permission denied (public key) fatal: The remote end hung up unexpectedly"
Then I looked up on the internet and found that I had to generate an ssh key for my account on GitHub. However, upon doing so, when I tried to do ssh-keygen -t rsa "email#youremail.com" it simply said ssh-keygen is not recognized. I tried doing mkdir C:\ssh but that didn't work. If it helps I'm using Ruby Rails and I'm on a Windows computer. Could anyone help me?
2012:
ssh-keygen.exe is part of msysgit:
C:\path\to\msysgit1.7.11\bin\ssh-keygen.exe
if your %PATH% includes C:\path\to\msysgit1.7.11\bin\, you will have ssh-keygen.
Update 2015:
ssh-keygen.exe is part of Git For Windows, whose releases include PortableGit-2.4.3.1-2nd-release-candidate-64-bit.7z
c:\path\to\PortableGit-2.4.3.1-2nd-release-candidate-64-bit\usr\bin\ssh-keygen.exe
That means the %PATH% must include c:\path\to\PortableGit-2.4.3.1-2nd-release-candidate-64-bit\usr\bin (without the ssh-keygen.exe)
As I explained before, Git for Windows will soon phase out msysgit.
I detailed in "Why is it that if you download Git 2.0 from the net, you always get a 1.9.4 installer package?" how this new version is based on the more recent msys2 project.
I just had this issue and thought I'd share what I thought was an easier way around this.
Open git-bash and run the same command with the addition of -C since you're commenting in your email address: ssh-keygen -t rsa -C "email#youremail.com" command. That's it.
git-bash should have been installed when you installed git. If you can't find it you can check C:\Program Files\Git\Git Bash
The first time I did this it failed to create the .ssh folder for me so I had to open a standard Command Prompt and mkdir C:\Users\yourusername\.ssh
I followed below in windows (With Git for Windows installed)
Run "Git Gui" (Start --> Git --> Git Gui)
Click Help and then Show SSH Key
Click Generate Key if you do not have one already
Note:- this creates the key files under your personal profile folder C:\Users\YourUserID\.ssh\
No need to add anything to environmental variables! Just open up git bash and perform command the ssh-keygen in there.
Link to download git bash here
I found an easy solution to fix this :
In the command prompt, go to your git\bin directory,
and then execute your commands from here
If you have installed Git, and is installed at C:\Program Files, follow as below
Go to "C:\Program Files\Git"
Run git-bash.exe, this opens a new window
In the new bash window, run "ssh-keygen -t rsa -C""
It prompts for file in which to save key, dont input any value - just press enter
Same for passphrase (twice), just press enter
id_rsa and id_rsa.pub will be generated in your home folder under .ssh
Just go to heroku.bat and add:
#SET PATH="D:\Program Files (x86)\Git\bin";%PATH% after #SET PATH=%HEROKU_RUBY%;%PATH%
in my case it's in D:\Program Files (x86)\Git\bin, change it to the path you've installed Git to. (i just left it with my path so it will be clearer on how to write this)
I think you can add the location of the file ssh-keygen.exe in the PATH environment variable. Follow the steps: Go to My Computer->Right click->Properties->Advanced System Settings->Click Environmental Variables. Now click PATH and then click EDIT. In the variable value field, go to the end and append ';C:\path\to\msysgit1.7.11\bin\ssh-keygen.exe' (without quotes)
don't do anything just type in your command prompt
C:\> sh
then you got like this
sh-4.4$
# type here
ssh-4.4$ ssh-keygen -t rsa -b 4096 -C "example#example.com"
this should must work.
For windows you can add this:
SET PATH="C:\Program Files\Git\usr\bin";%PATH%
You probably should check this. Windows doesn't have that command built in.
I got it fixed by just adding ssh-keygen to my environment variables.
for those who does not choose BASH HERE option. type sh in cmd then they should have ssh-keygen.exe accessible
In my machine, ssh-keygen was available from powershell.

Resources