[英]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.
我正在为我的项目创建克隆。 到目前为止,我已经完成了所有步骤,但我一直从 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
没有任何东西被克隆。
顺便说一句: TortoisePLink
在此消息出现之前出现并询问我:“ login as:
”(我认为此信息是在命令中给出的,即: Administrator@blahblah
。
我的主变量设置为正确的位置:从 Git Bash shell 开始:
echo $HOME
/c/SSH/home/Administrator
我也尝试过使用 Putty 的 plink 而不是TortoisePLink
(在 Git 和TortoiseGit
的安装中)。 这次错误被缩小到:
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
在偶然发现明显的答案之前,我与这个问题斗争了几个小时。 我遇到的问题是我在生成密钥和使用 git 之间使用了不同的 ssh 实现。
我在命令提示符下使用 ssh-keygen 来生成我的密钥,但是当我尝试“git clone ssh://...”时,我得到了与您相同的结果,提示输入密码和消息“fatal: The remote最后意外挂断”。
通过执行 Windows 的“where”命令确定正在使用的 ssh 窗口。
C:\where ssh
C:\Program Files (x86)\Git\bin\ssh.exe
第二行告诉您将执行哪个确切的程序。
接下来,您需要确定 git 正在使用哪个 ssh。 通过以下方式查找:
C:\set GIT_SSH
GIT_SSH=C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe
现在你看到了问题所在。
要更正此问题,只需执行:
C:\set GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
要检查是否应用了更改:
C:\set GIT_SSH
GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
现在 git 将能够使用您之前生成的密钥。
到目前为止,此修复仅适用于当前窗口。 要完全修复它,您需要更改环境变量。
现在,您以后打开的任何命令窗口都将具有正确的设置。
希望这可以帮助。
由于这在搜索结果中不断出现以使 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
到您想要保存 repo 的根级别(类似于: C:\\code\\github\\
),然后
类型:
eval $(ssh-agent -s) && ssh-add "C:\\Users\\YOURNAMEHERE\\.ssh\\github_rsa"
3. 输入:(来自 repo 的 SSH 链接)
git clone git@github.com:RepoName/Project.git
您在此处使用智能引号“
而不是"
:
git.exe clone -v “ssh://
^^^
确保使用普通的双引号。
我在“C:/Program Files/Git/usr/bin”目录中找到了我的 ssh.exe
如果安装了 Windows 版 Git,请运行 Git Bash shell
:
bash
您可以在 Bash shell 中运行 ssh(Bash 知道 ssh 的路径)
要知道 ssh 的确切路径,请在 Bash shell 中运行“where”命令:
$ where ssh
你得到:
c:\Program Files\Git\usr\bin\ssh.exe
我试图用上面的一些答案来解决我的问题,但由于某种原因它不起作用。 我确实切换到使用 git 扩展,这是我遵循的步骤。
Tools -> Settings -> SSH -> Other ssh client
C:\\Program Files\\Git\\usr\\bin\\ssh.exe
我想这些步骤与上面解释的相同。 唯一的区别是我使用了 Git 扩展用户界面而不是终端。 希望这有帮助。
当我输入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
删除/移动这些 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
这为我解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.