[英]Git with SSH on 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'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:到目前为止,我已经完成了所有步骤,但我一直从 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, ie: Administrator@blahblah
.顺便说一句: TortoisePLink
在此消息出现之前出现并询问我:“ login as:
”(我认为此信息是在命令中给出的,即: Administrator@blahblah
。
My home variable is set to the correct place: From a Git Bash shell:我的主变量设置为正确的位置:从 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).我也尝试过使用 Putty 的 plink 而不是TortoisePLink
(在 Git 和TortoiseGit
的安装中)。 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.我遇到的问题是我在生成密钥和使用 git 之间使用了不同的 ssh 实现。
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".我在命令提示符下使用 ssh-keygen 来生成我的密钥,但是当我尝试“git clone ssh://...”时,我得到了与您相同的结果,提示输入密码和消息“fatal: The remote最后意外挂断”。
Determine which ssh windows is using by executing the Windows "where" command.通过执行 Windows 的“where”命令确定正在使用的 ssh 窗口。
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.接下来,您需要确定 git 正在使用哪个 ssh。 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.现在 git 将能够使用您之前生成的密钥。
This fix is so far only for the current window.到目前为止,此修复仅适用于当前窗口。 To fix it completely you need to change your environment variable.要完全修复它,您需要更改环境变量。
Now any future command windows you open will have the correct settings.现在,您以后打开的任何命令窗口都将具有正确的设置。
Hope this helps.希望这可以帮助。
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.由于这在搜索结果中不断出现以使 git 和 github在 Windows 上与 SSH 一起工作(并且因为我不需要上述指南中的任何内容),我添加了以下简单的解决方案。
(Microsoft says they are working on adding SSH to Visual Studio, and GitHub for Windows still doesn't support SSH...) (微软表示他们正在努力将 SSH 添加到 Visual Studio,而 GitHub for Windows 仍然不支持 SSH...)
1. I installed "git for Windows" (which includes ssh and a bash shell) 1.我安装了“git for Windows”(包括 ssh 和 bash shell)
https://git-scm.com/download/win 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
) 2.从包含的 bash shell(对我来说,它安装在: 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 cd
到您想要保存 repo 的根级别(类似于: C:\\code\\github\\
),然后
Type:类型:
eval $(ssh-agent -s) && ssh-add "C:\\Users\\YOURNAMEHERE\\.ssh\\github_rsa"
3. Type: (the SSH link from the repo) 3. 输入:(来自 repo 的 SSH 链接)
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.确保使用普通的双引号。
我在“C:/Program Files/Git/usr/bin”目录中找到了我的 ssh.exe
If Git for windows is installed, run Git Bash shell
:如果安装了 Windows 版 Git,请运行 Git Bash shell
:
bash
You can run ssh from within Bash shell (Bash is aware of the path of ssh)您可以在 Bash shell 中运行 ssh(Bash 知道 ssh 的路径)
To know the exact path of ssh, run "where" command in Bash shell:要知道 ssh 的确切路径,请在 Bash shell 中运行“where”命令:
$ 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.我确实切换到使用 git 扩展,这是我遵循的步骤。
Tools -> Settings -> SSH -> Other ssh client
我去了Tools -> Settings -> SSH -> Other ssh client
C:\\Program Files\\Git\\usr\\bin\\ssh.exe
将此值设置为C:\\Program Files\\Git\\usr\\bin\\ssh.exe
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.唯一的区别是我使用了 Git 扩展用户界面而不是终端。 Hope this help.希望这有帮助。
When I typed where ssh
it showed me multipe ssh.exe
当我输入where ssh
时,它显示了多重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:删除/移动这些 exe 有助于:
# 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.这为我解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.