在 Windows 上使用 SSH 的 Git [英] Git with SSH on Windows

查看:26
本文介绍了在 Windows 上使用 SSH 的 Git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经浏览了 Tim Davis 提供的优秀指南,它是关于配置 Git 以在 Windows 下与 SSH 一起使用,以便生成 Git 服务器,以便为我的 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.

我正在为我的项目创建一个克隆.到目前为止,我已经完成了所有步骤,但我一直在从 TortoiseGit 获取此信息:

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:GitTestmyapp"

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.

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.

我的 home 变量设置到了正确的位置:来自 Git Bash shell:

My home variable is set to the correct place: From a Git Bash shell:

echo $HOME
/c/SSH/home/Administrator

我也尝试过使用 Putty 的 plink 而不是 TortoisePLink(在 Git 和 TortoiseGit 的安装中).这次错误缩小为:

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:GitTestmyapp"

Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly

推荐答案

我与这个问题搏斗了几个小时,才偶然发现了明显的答案.我遇到的问题是我在生成密钥和使用 git 之间使用了不同的 ssh 实现.

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.

我在命令提示符下使用 ssh-keygen 来生成我的密钥,但是当我尝试git clone ssh://..."时,我得到了与您相同的结果,提示输入密码和消息fatal": 远端意外挂断.

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".

通过执行 Windows 的where"命令确定正在使用的 ssh 窗口.

Determine which ssh windows is using by executing the Windows "where" command.

C:where ssh
C:Program Files (x86)Gitinssh.exe

第二行告诉您将执行哪个确切的程序.

The second line tells you which exact program will be executed.

接下来您需要确定 git 正在使用哪个 ssh.通过以下方式查找:

Next you need to determine which ssh that git is using. Find this by:

C:set GIT_SSH
GIT_SSH=C:Program FilesTortoiseSVNinTortoisePlink.exe

现在你看到了问题.

要更正此问题,只需执行:

To correct this simply execute:

C:set GIT_SSH=C:Program Files (x86)Gitinssh.exe

要检查是否应用了更改:

To check if changes are applied:

C:set GIT_SSH
GIT_SSH=C:Program Files (x86)Gitinssh.exe

现在 git 将能够使用您之前生成的密钥.

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.

  1. 打开 Windows 资源管理器
  2. 右键单击计算机"并选择属性"
  3. 点击左侧的高级系统设置链接
  4. 点击环境变量...按钮
  5. 在系统变量部分选择 GIT_SSH 变量并按下编辑...按钮
  6. 更新变量值.
  7. 按确定关闭所有窗口

现在您打开的任何未来命令窗口都将具有正确的设置.

Now any future command windows you open will have the correct settings.

希望这会有所帮助.

这篇关于在 Windows 上使用 SSH 的 Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆