44

我在 Windows XP(msysGit 1.7.11,TortoiseGit 1.7.14)上设置了一个 git 环境,并试图实现以下几点:

  • 与默认 22 不同的端口上的 ssh 连接
  • 由 ssh-agent 处理的 ssh 身份验证

所以我创建了一个~/.ssh/config文件:

Host gitbox
   User gitolite
   Hostname XX.XX.XX.XX
   Port 154
   PreferredAuthentications publickey
   IdentityFile "/c/Documents and Settings/kraymer/.ssh/id_rsa"

使用 git bash CLI 时,一切都按预期工作。

我正在与 TortoiseGit 斗争。
我首先使用 Plink 安装 TortoiseGit 并使用 Pageant 加载 ssh 私钥。自动身份验证(选美)工作但设置失败,因为 TortoiseGit 无法识别格式为gitolite@gitbox/repo.git的 git repos url 。

然后我决定使用 openssh 客户端安装 TortoiseGit,以便ssh 客户端可以读取配置文件,并模仿 git CLI 设置。
我在 TortoiseGit 设置中选择了msys git 附带的 ssh.exe 作为 ssh 客户端。
执行 agit pull时,远程 url 现在已解析,但在我希望 ssh-agent 自动身份验证发生时询问密码密码。

https://dl.dropbox.com/u/1026715/tortoisegit.png

是否可以让 TortoiseGit 与 ssh-agent 一起使用?
或者让 TortoiseGit (Plink) 知道.ssh/config

编辑#1

按照@VonC 的建议,我配置了我的 $HOME 变量。
当我在 TortoiseGit 中单击Show environment variables时,我现在有:

 HOME=C:\Documents and Settings\kraymer  
 HOMEDRIVE=C: 
 HOMEPATH=\Documents and Settings\kraymer 

git pull仍然需要我输入密码。

4

9 回答 9

119

No tweaks needed.

Just make TortoiseGit point to the same ssh client used by git itself, see the screenshot:

在此处输入图像描述

This should be C:\Program Files\Git\usr\bin\ssh.exe in latest version of Git as mentioned by Aleksey Kontsevich in the comments.

于 2015-10-25T10:28:53.787 回答
4

I first installed TortoiseGit with Plink and using Pageant to load ssh private key. The automatic authentication (Pageant) worked but setup was a fail as TortoiseGit don't recognize git repos url formatted as gitolite@gitbox/repo.git.

I finally found a workaround which consist to create a PuTTY session with the same name that the ssh alias (ie gitbox in the question).
This way I can clone as git clone gitbox/monrepo in the CLI and the origin syntax is correctly handled by TortoiseGit.

于 2013-01-09T16:51:38.543 回答
4

1) Cygwin

Use approach described in the following article: https://help.github.com/articles/working-with-ssh-key-passphrases

Password will be asked only once on the cygwin session startup. !!! Before exiting cygwin session don't forget to kill ssh-agent process (use ps for find process PID and kill -9).

We are using separate approach for cygwin, because cygwin by some reason doesn't see processes started externally in windows environment.

2, 3) MsysGit, TortoiseGit

Useful link: http://dogbiscuit.org/mdub/weblog/Tech/WindowsSshAgent

Install MsysGit. Install TortoiseGit (check openssh instead of plink during installation). !!! Check systems variables. If there is GIT_SSH variable present - remove it.

Go to TortoiseGit->Settings->General

Set Git exe Path to /bin Set External dll path to /mingw/bin

Go to TortoiseGit->Settings->Network Set SSH Client property to /bin/ssh.exe

Define system variable SSH_AUTH_SOCKS=C:\temp.ssh-socket

Start cmd.exe and execute following commands(since we installed MsysGit all following commands are accessible in cmd - /bin is added to system PATH variable):

# following command is required to execute for avoiding Address already bind message when ssh-agen is not started yet but .ssh-socket exists after previous agent session
rm "%SSH_AUTH_SOCK%"

# Starting ssh-agent
ssh-agent -a "%SSH_AUTH_SOCK%"

# Adding our openssh key
ssh-add "%USERPROFILE%\.ssh\id_rsa"

# Type password for your key

That's it. From that moment you can execute git push, git pull from TortoiseGit and MsysGit without prompting passphrase.

When ssh-agent is no longer required you can kill it through windows task manager.

于 2013-02-16T17:48:09.393 回答
3

None of the above answers worked for me.

I created this batch file to solve the problem.

CALL "C:\Program Files\Git\cmd\start-ssh-agent.cmd"
SETX SSH_AUTH_SOCK "%SSH_AUTH_SOCK%"
SETX SSH_AGENT_PID "%SSH_AGENT_PID%"

Run this once, and enter your passphrase.

Then you can use tortoisegit with openssh without having to enter your passphrase for every operation.

于 2016-07-07T22:55:59.587 回答
3

There seems to be a whole variety of options to solve this. As none of the above have worked for me, I tought I'd share what helped for me.

Screenshot: Network settings / Git SSH Client

In Settings... -> Network -> SSH -> SSH client, set the client to C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe. Using Pageant, you're then automatically authenticated as expected, otherwise you are prompted for your private key passphrase. Make sure the "Autoload Putty Key" option is checked in the push dialog.

于 2016-11-19T01:39:33.927 回答
2

Make sure to launch your TortoiseGit in an environment where HOME is defined, and reference the parent directory of .ssh.
This is important since, on Windows, HOME isn't defined by default.

See as an example: "Auth fails on Windows XP with git and tortoisegit".
(Other possible sources: "How to I tell Git for Windows where to find my private RSA key?")

于 2012-11-23T07:35:49.210 回答
2

Since the explanations here are a bit outdated, I decided to post my solution.

I am using Git Bash and TortoiseGit 2.8.0 in Windows 10, which are common nowadays.

I set ssh.exe as SSH client in Settings->Network as explained in previous posts.

I created a script with the following commands, as explained in a previous comment. You might also want to set a HOME environment variable, in case your system does not do it automatically. Assuming your home is in drive H:\ you can add the following lines:

SETX HOME /h
CALL "C:\Program Files\Git\cmd\start-ssh-agent.cmd"
SETX SSH_AUTH_SOCK "%SSH_AUTH_SOCK%"
SETX SSH_AGENT_PID "%SSH_AGENT_PID%"

Win logo我使用+将脚本添加R shell:startup到启动文件夹中。或者,您可以将脚本添加到注册表以保证它在其他进程之前运行:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

确保键入exit以关闭控制台并允许为将来的进程设置变量。

于 2019-03-20T16:28:46.537 回答
2

Windows10 系统
#TortoiseGit
在网络部分
从: C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe
到: “C:\Users{user}\AppData\Local\Programs\Git\usr\bin\ssh.exe”

在此处输入图像描述

于 2021-10-05T21:28:45.217 回答
1

如果您在存储库中使用 RSA 密钥,请按上述说明在脚本末尾添加^

CALL "C:\Program Files\Git\cmd\start-ssh-agent.cmd"
...
"C:\Program Files\Git\usr\bin\ssh-add"  ~/.ssh/myid.rsa

适用于 Git 2.24.0、TortoiseGit 2.9.0、Windows 10 且不使用任何 Putty。

于 2019-11-05T20:29:23.173 回答