在 Windows 上使用 SSH 进行 Git

发布于 2024-08-25 19:28:46 字数 1542 浏览 7 评论 0原文

我已经阅读了 提供的优秀指南作者: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

烟燃烟灭 2024-09-01 19:28:46

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

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

通过执行 Windows“where”命令确定正在使用哪个 ssh windows。

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 将能够使用您之前生成的密钥。

到目前为止,此修复仅适用于当前窗口。要完全修复它,您需要更改环境变量。

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

现在,您以后打开的任何命令窗口都将具有正确的设置。

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.

  1. Open Windows explorer
  2. Right-click Computer and select Properties
  3. Click Advanced System Settings link on the left
  4. Click the Environment Variables... button
  5. In the system variables section select the GIT_SSH variable and press the Edit... button
  6. Update the variable value.
  7. Press OK to close all windows

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

一页 2024-09-01 19:28:46

由于这个问题不断出现在让 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\), and

Type:

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

我很坚强 2024-09-01 19:28:46

您在此处使用智能引号 而不是 "

git.exe clone -v “ssh://
                ^^^ 

确保您使用普通的旧双引号。

you are using a smart quote instead of " here:

git.exe clone -v “ssh://
                ^^^ 

Make sure you use the plain-old-double-quote.

梨涡 2024-09-01 19:28:46

我在 C:/Program Files/Git/usr/bin 目录中找到了我的 ssh.exe

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

庆幸我还是我 2024-09-01 19:28:46

如果安装了 Windows 版 Git,请运行 Git Bash shell

  bash

您可以从 Bash shell 中运行 ssh(Bash 知道 ssh 的路径)

要了解 ssh 的确切路径,请运行“where”命令在 Bash shell 中:

  $ where ssh

你得到:

  c:\Program Files\Git\usr\bin\ssh.exe

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
梦一生花开无言 2024-09-01 19:28:46

当我输入 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

这为我解决了问题。

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.

梦断已成空 2024-09-01 19:28:46

我试图用上面的一些答案来解决我的问题,但由于某种原因它不起作用。我确实改用了 git 扩展,这是我遵循的步骤。

  1. 我转到工具 ->设置-> SSH->其他ssh客户端
  2. 将此值设置为C:\Program Files\Git\usr\bin\ssh.exe
  3. 应用

我猜这个步骤与上面解释的相同。唯一的区别是我使用了 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.

  1. I went to Tools -> Settings -> SSH -> Other ssh client
  2. Set this value to C:\Program Files\Git\usr\bin\ssh.exe
  3. 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.

瑾夏年华 2024-09-01 19:28:46

如果它对任何人有帮助,我需要 Git 来使用 Windows 包含的 OpenSSH,因为使用 Nitrokey 智能卡GnuPG 密钥和 gpg-agent (与此问题无关)。

检查它的工作原理后:

set GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe

我只需将它添加到“我的电脑=>”中的环境变量中即可。属性=>高级属性=>环境

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:

set GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe

I only had to add it to the environment variables in My Computer => Properties => Advanced Properties => Environment

双手揣兜 2024-09-01 19:28:46

不确定我的回答在这里是否有意义..
但我在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文