在 Windows 上使用 SSH 进行 Git
我已经阅读了 提供的优秀指南作者:Tim Davis,内容是关于将 Git 配置为在 Windows 下与 SSH 一起工作,以便生成一个 Git 服务器,以便为我的 DVCS 提供一个主要位置。
我正在为我的项目创建克隆。到目前为止,我已经完成了所有步骤,但我不断从 TortoiseGit 得到这个:
git.exe clone -v “ssh://[email protected]:22/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
bash: [email protected]: command not found
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
Success
并且没有任何内容被克隆。
顺便说一句:TortoisePLink
在此消息出现之前出现并询问我:“登录为:
”(我认为此信息在命令中给出,即:Administrator@blahblah
。
我的 home 变量设置为正确的位置: 从 Git Bash shell:
echo $HOME
/c/SSH/home/Administrator
我还尝试使用 Putty 的 plink 而不是 TortoisePLink
(在 Git 和 TortoiseGit
的安装中)。这次错误缩小到:
git.exe clone -v “ssh://[email protected]: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'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://[email protected]:22/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
bash: [email protected]: 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://[email protected]: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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
在偶然发现明显的答案之前,我与这个问题斗争了几个小时。我遇到的问题是我在生成密钥和使用 git 之间使用了不同的 ssh 实现。
我在命令提示符下使用 ssh-keygen 来生成密钥,但是当我尝试“git clone ssh://...”时,我得到了与您相同的结果,提示输入密码和消息“致命:远程结果意外挂断了”。
通过执行 Windows“where”命令确定正在使用哪个 ssh windows。
第二行告诉您将执行哪个确切的程序。
接下来您需要确定 git 使用的是哪个 ssh。找到这个:
现在你看到问题了。
要纠正此问题,只需执行:
检查是否应用了更改:
现在 git 将能够使用您之前生成的密钥。
到目前为止,此修复仅适用于当前窗口。要完全修复它,您需要更改环境变量。
现在,您以后打开的任何命令窗口都将具有正确的设置。
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.
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:
And now you see the problem.
To correct this simply execute:
To check if changes are applied:
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.
Now any future command windows you open will have the correct settings.
由于这个问题不断出现在让 git 和 github 在 Windows 上使用 SSH 的搜索结果中(并且因为我不需要上面指南中的任何内容),所以我添加了以下简单的解决方案。
(微软表示他们正在努力将 SSH 添加到 Visual Studio,而 GitHub for Windows 仍然不支持 SSH...)
1. 我安装了“git for Windows” (其中包括 ssh 和 bash shell)
https://git-scm.com/download/win
2. 从附带的 bash shell(对我来说,安装在:
C:\Program Files\Git\git-bash.exe
)cd
到您想要保存存储库的根级别(例如:C:\code\github\
),然后类型:
eval $ (ssh-agent -s) && ssh-add "C:\Users\YOURNAMEHERE\.ssh\github_rsa"
3. 类型:(来自存储库的 SSH 链接)
git克隆 [电子邮件受保护]:RepoName/Project.git
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\
), andType:
eval $(ssh-agent -s) && ssh-add "C:\Users\YOURNAMEHERE\.ssh\github_rsa"
3. Type: (the SSH link from the repo)
git clone [email protected]:RepoName/Project.git
您在此处使用智能引号
“
而不是"
:确保您使用普通的旧双引号。
you are using a smart quote
“
instead of"
here:Make sure you use the plain-old-double-quote.
我在
C:/Program Files/Git/usr/bin
目录中找到了我的ssh.exe
。I've found my
ssh.exe
inC:/Program Files/Git/usr/bin
directory.如果安装了 Windows 版 Git,请运行 Git
Bash shell
:您可以从 Bash shell 中运行 ssh(Bash 知道 ssh 的路径)
要了解 ssh 的确切路径,请运行“where”命令在 Bash shell 中:
你得到:
If Git for windows is installed, run Git
Bash shell
: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:
you get:
当我输入
where ssh
时,它显示了多个ssh.exe
删除/移动这些 exe 有所帮助:
这为我解决了问题。
When I typed
where ssh
it showed me multipessh.exe
Deleting / moving these exe helped:
This solved the issue for me.
我试图用上面的一些答案来解决我的问题,但由于某种原因它不起作用。我确实改用了 git 扩展,这是我遵循的步骤。
工具 ->设置-> SSH->其他ssh客户端
C:\Program Files\Git\usr\bin\ssh.exe
我猜这个步骤与上面解释的相同。唯一的区别是我使用了 Git 扩展用户界面而不是终端。希望这有帮助。
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.
Tools -> Settings -> SSH -> Other ssh client
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. Hope this help.
如果它对任何人有帮助,我需要 Git 来使用 Windows 包含的 OpenSSH,因为使用 Nitrokey 智能卡GnuPG 密钥和 gpg-agent (与此问题无关)。
检查它的工作原理后:
我只需将它添加到“我的电脑=>”中的环境变量中即可。属性=>高级属性=>环境
In case it helps anyone, I needed Git to use the Windows's included OpenSSH, because of using a Nitrokey smartcard with GnuPG keys and gpg-agent (not relevant to this question).
After cheking it worked with:
I only had to add it to the environment variables in My Computer => Properties => Advanced Properties => Environment
不确定我的回答在这里是否有意义..
但我在 GIT_SSH 指向 TortoisePlink.exe 时遇到了同样的问题。
我通过转到 SourceTree 工具的选项解决了这个问题,在该选项中我意外地将 SSH 客户端的 SSH 客户端配置配置为 Putty/Plink。
我猜这是默认的。
当我将其更改为 OpenSSH 时,我能够从 Bitbucket 克隆我的存储库。
not sure if my answer makes sense here..
but I got the same issue with GIT_SSH pointing to TortoisePlink.exe.
I got it solved by going to options of SourceTree tool where I accidently somehow configured SSH Client Configuration for SSH Client to Putty/Plink.
I guess it was the default.
When I changed it to OpenSSH I was able to clone my repo from Bitbucket.