通过 ssh 在 Windows 上使用 Mercurial“hg clone”,并带有 plink 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2799822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mercurial "hg clone" on Windows via ssh with plink issue
提问by Kyle Tolle
I have a Windows Server 2008 machine (iis7) that has CopSSH set up on it. To connect to it, I have a Windows 7 machine with Mercurial 1.5.1 (and TortoiseHg) installed.
我有一台装有 CopSSH 的 Windows Server 2008 机器 (iis7)。为了连接到它,我有一台安装了 Mercurial 1.5.1(和 TortoiseHg)的 Windows 7 机器。
I can connect to the server using PuTTY with a non-standard ssh port and a .ppk file just fine. So I know the server can be SSH'd into.
我可以使用 PuTTY 与非标准 ssh 端口和 .ppk 文件连接到服务器就好了。所以我知道服务器可以通过 SSH 连接。
Next, I wanted to use the CLI to connect via hg clone to get a private repo. I've seen elsewhere that you need to have ssh configured in your mercurial.ini file, so my mercurial.ini has a line: ssh = plink.exe -ssh -C -l username -P #### -i "C:/Program Files/PuTTY/Key Files/KyleKey.ppk"
Note:username
is filled in with the username I set up via copSSH.####
is filled in with the non-standard ssh port I've defined for copSSH.
接下来,我想使用 CLI 通过 hg clone 进行连接以获取私有存储库。我在别处看到你需要在你的 mercurial.ini 文件中配置 ssh,所以我的 mercurial.ini 有一行:ssh = plink.exe -ssh -C -l username -P #### -i "C:/Program Files/PuTTY/Key Files/KyleKey.ppk"
注意:username
填写的是我通过 copSSH 设置的用户名。####
填充了我为 copSSH 定义的非标准 ssh 端口。
I try to do the command hg clone ssh://inthom.com
but I get this error:remote: bash: inthom.com: command not found
abort: no suitable response from remote hg!
我尝试执行命令,hg clone ssh://inthom.com
但出现此错误:remote: bash: inthom.com: command not found
abort: no suitable response from remote hg!
It looks like hg or plink parses the hostname such that it thinks that inthom.com is a command instead of the server to ssh to. That's really odd.
看起来 hg 或 plink 会解析主机名,以至于它认为 inthom.com 是一个命令,而不是 ssh 到的服务器。这真的很奇怪。
Next, I tried to just use plink to connect by plink -P #### ssh://inthom.com
, and I am then prompted for my username, and next password. I enter them both and then I get this error:bash: ssh://inthom.com: No such file or directory
接下来,我尝试仅使用 plink 进行连接plink -P #### ssh://inthom.com
,然后系统会提示我输入用户名和下一个密码。我输入它们,然后出现此错误:bash: ssh://inthom.com: No such file or directory
So now it looks like plink doesn't parse the hostname correctly.
所以现在看起来 plink 没有正确解析主机名。
I fiddled around for a while trying to figure out how to do call hg clone with an empty ssh:// field and eventually figured out that this command allows me to reach the server and clone a test repo on the inthom.com server:hg clone ssh://!/Repos/test
我摆弄了一段时间试图弄清楚如何使用空的 ssh:// 字段调用 hg clone 并最终发现此命令允许我访问服务器并在 inthom.com 服务器上克隆一个测试存储库:hg clone ssh://!/Repos/test
!
is the character I've found that let's me leave the hostname blank, but specify the repo folder to clone.
!
是我发现的字符,让我将主机名留空,但指定要克隆的 repo 文件夹。
What I really don't understand is how plink knows what server to ssh to at all. neither my mercurial.ini nor the command specify a server. None of the hg clone
examples I've seen have a !
character. They all use an address, which makes sense, so you can connect to anyrepo via ssh that you want to clone.
我真正不明白的是 plink 如何知道 ssh 到哪个服务器。我的 mercurial.ini 和命令都没有指定服务器。hg clone
我见过的例子都没有一个!
字符。它们都使用一个地址,这是有道理的,因此您可以通过要克隆的 ssh连接到任何存储库。
My only guess is that it somehow defaults to the last server I used PuTTY to SSH to, but I SSH'd into another server, and then tried to use plink to get to it, but plink still defaults to inthom.com (verified with the -v arg to plink). So I am at a loss as to how plink gets this server value at all.
我唯一的猜测是它以某种方式默认为我使用 PuTTY SSH 连接到的最后一台服务器,但我通过 SSH 连接到另一台服务器,然后尝试使用 plink 访问它,但 plink 仍然默认为 inthom.com(已通过-v arg 到 plink)。所以我完全不知道 plink 如何获得这个服务器值。
For "fun", I tried using TortoiseHg and can only clone a repo when I use ssh://!/Repos/test
as the Source.
为了“乐趣”,我尝试使用 TortoiseHg 并且只能在我ssh://!/Repos/test
用作源时克隆一个 repo 。
Now, you can see that, since plink doesn't parse the hostname correctly, I had to specify the port number and username in the mercurial.ini file, instead of in the hostname like [email protected]:#### like you'd expect to. Trying to figure this out at first drove me insane, because I would get errors that the host couldn't be reached, which I knew shouldn't be the case.
现在,您可以看到,由于 plink 没有正确解析主机名,我必须在 mercurial.ini 文件中指定端口号和用户名,而不是像 [email protected]:#### 这样的主机名你会期望的。一开始试图弄清楚这一点让我发疯了,因为我会收到无法联系到主机的错误,我知道不应该出现这种情况。
My question is how can I configure my setup so that ssh://[email protected]:####/Repos/test is parsed correctly as the username, hostname, port number, and repo to copy? Is it something wrong with the version of plink that I'm using, or is there some setting I may have messed up? If it is plink's fault, is there an alternative tool I can use?
我的问题是如何配置我的设置,以便 ssh://[email protected]:####/Repos/test 被正确解析为用户名、主机名、端口号和要复制的存储库?我正在使用的 plink 版本有问题,还是我可能搞砸了某些设置?如果是 plink 的错,有没有我可以使用的替代工具?
I'm going to try to get my friend set up to connect to this same repo, so I'd like to have a clean solution instead of this !
business. Especially when I have no idea how plink gets this default server, so I'm not sure if he'd even be able to get to inthom.com correctly.
我将尝试让我的朋友设置连接到同一个 repo,所以我想要一个干净的解决方案而不是这个!
业务。特别是当我不知道 plink 如何获得这个默认服务器时,所以我不确定他是否能够正确访问 inthom.com。
PS. I've had to use a ton of different tutorials to even get to this stage. Therefore, I haven't tried pushing any changes to the server yet. Hopefully I'll get this figured out and then I can try pushing changes to the repo.
附注。我什至不得不使用大量不同的教程才能达到这个阶段。因此,我还没有尝试将任何更改推送到服务器。希望我能弄清楚这一点,然后我可以尝试将更改推送到 repo。
回答by Hrvoje Varga
I know I am late but better now then never. OK, so... Command for connecting to Mercurial SSH
我知道我迟到了,但现在比永远都好。好的,所以...用于连接到 Mercurial SSH 的命令
ssh = plink.exe -ssh -C -l username -P #### -i "C:/Program Files/PuTTY/Key Files/KyleKey.ppk"
ssh = plink.exe -ssh -C -l 用户名 -P #### -i "C:/Program Files/PuTTY/Key Files/KyleKey.ppk"
is perfectly OK, but the problem is with Plink.
完全没问题,但问题出在 Plink 上。
Plink have problems with folders that have spaces in their names. So, the problem is in
Plink 遇到名称中包含空格的文件夹的问题。所以,问题出在
"C:/Program Files/PuTTY/Key Files/KyleKey.ppk"
“C:/Program Files/PuTTY/Key Files/KyleKey.ppk”
You have two options:
您有两个选择:
You can move this "KyleKey.ppk" file into a path with no spaces in name. For example, you can move this file in "C:\" or "D:\Path\Without\Space\In\Name".
You can use Windows short path names. For example, I have
ssh = "C:\Progra~2\Plink\Plink.exe" -ssh -i "C:\Progra~2\PuTTYgen\hrle.ppk"
in my "Mercurial.ini".
"C:\Progra~2" is "C:\Program Files (x86)".
您可以将此“KyleKey.ppk”文件移动到名称中没有空格的路径中。例如,您可以将此文件移动到“C:\”或“D:\Path\Without\Space\In\Name”中。
您可以使用 Windows 短路径名。例如,我有
ssh = "C:\Progra~2\Plink\Plink.exe" -ssh -i "C:\Progra~2\PuTTYgen\hrle.ppk"
在我的“Mercurial.ini”中。
“C:\Progra~2”是“C:\Program Files (x86)”。
Plink will hang if SSH private key is protected with a password.
如果 SSH 私钥受密码保护,Plink 将挂起。
And also, you must add this server to know server list before you even use Plink in conjunction with TortoiseHg or some other GUI tool like MercurialEclipse. If you fail to do that Plink will hang waiting for you response which you can not give because you work with TortoiseHg and not on the command line. More on this subjet in AccessingSshRepositoriesFromWindows.
而且,在将 Plink 与 TortoiseHg 或其他一些 GUI 工具(如 MercurialEclipse)结合使用之前,您必须添加此服务器以了解服务器列表。如果你不这样做,Plink 将挂起等待你的响应,你不能给出,因为你使用 TortoiseHg 而不是在命令行上。在AccessingSshRepositoriesFromWindows 中有更多关于这个子集的信息。
回答by Sean Madden
With plink you do not need to use the ssh:// protocol identifier. You can simply use {user}@{host}:{path} format and it will work fine.
使用 plink,您不需要使用 ssh:// 协议标识符。您可以简单地使用 {user}@{host}:{path} 格式,它会正常工作。
Example:
例子:
plink -ssh -C -l {username} -pw {pass} -P 22 -i "C:/Program Files/PuTTY/Key Files/KyleKey.ppk" inthom.com:/Repos/test
plink -ssh -C -l {username} -pw {pass} -P 22 -i "C:/Program Files/PuTTY/Key Files/KyleKey.ppk" inthom.com:/Repos/test
replace {username} with the user and {pass} with the password as well.
用用户替换 {username},用密码替换 {pass}。
回答by Sean Madden
yo, i had the same problem. What was wrong with my setup is that plink was using the default server set in putty instead of the one I was providing. I had to open putty and remove the default server and then save. Try to use plink without a server.. if your command passes, you have a default server..
哟,我有同样的问题。我的设置有什么问题是 plink 使用的是在 putty 中设置的默认服务器,而不是我提供的服务器。我不得不打开腻子并删除默认服务器,然后保存。尝试在没有服务器的情况下使用 plink .. 如果您的命令通过,则您有一个默认服务器..