如何在没有 PuTTY 的情况下从命令行使用 TortoiseHg (Pageant)

How to use TortoiseHg from command line without PuTTY (Pageant)

之前我使用 Mercurial 命令行安装,默认的 ssh 客户端和密钥位置在 ~/.ssh 中对我来说效果很好。

我在我的新笔记本电脑上安装了 TortoiseHg。现在任何远程请求(如 hg pull,或 hg incoming)都会生成 PuTTY Fatal Error:

Disconnected: No supported authentication methods available (server sent: publickey)

如果我尝试直接通过 ssh 访问存储库,结果非常相似: ssh -vT git@bitbucket.org

使用Pageantplink)可以解决问题:运行它并添加腻子键,或添加pageantplink) 到 Mercurial 配置文件。

但是,我正在寻找如何以旧方式工作,没有 pageant 或 plink,只使用默认的 ssh 密钥位置?

不,除了 TortoiseHg 本身之外,如果不安装或使用 一些 软件,就没有办法做到这一点

Mercurial 本身不实现 SSH。在 Unix 上,它只运行 ssh 并期望已经安装了一个合适的客户端(这是一个安全的选择,因为绝大多数 Unix 系统要么预装了 SSH 客户端,要么可以相对容易地安装一个)。在 Windows 上,这不是一个合理的假设,因此 TortoiseHg bundles a client:

SSH is a symmetrical peer-to-peer secure tunnel. SSH clients and servers have their own key management systems, so Mercurial does not get involved with password prompts when SSH is used. This is problematic on Windows and thus TortoiseHg bundles the TortoisePlink SSH client with its Windows installers. TortoisePlink is a port of the Plink SSH client that uses dialog prompts for host-key authorizations and passphrase prompts. TortoisePlink (developed by the TortoiseSVN project) can use the other SSH tools that are part of the Plink toolchain, including the Pageant key agent.

如果您不使用 TortoisePlink,您很可能没有 TortoiseHg 能够连接的 SSH 客户端。而且,如果您不使用 Pageant,则没有保存密钥的系统; TortoisePlink 不使用 ~/.ssh 因为那不是 Windows 做事的方式。

看起来与 git 相反 Mercurial 不提供自己的 ssh 客户端,因此必须使用 Plink 和 Pageant,除了两个解决方法:

  1. Use TortoisePlink as ssh client with explicit key reference in Mercurial config (%USERPROFILE%\.hgrc%USERPROFILE%\Mercurial.ini):

    [ui]

    ssh = "C:\Program Files\TortoiseHg\lib\TortoisePlink.exe" -ssh -i %USERPROFILE%.ssh\id_rsa.ppk

  2. 如果您已经安装了gitcygwin(或任何其他在Windows上使用ssh的方式),则可以使用第三方ssh客户端Mercurial 配置中的指向路径:

    [ui]

    ssh = "C:\Program Files (x86)\Git\bin\ssh.exe"

    # or

    # ssh = "PATH_TO_ANY_OTHER_SSH_CLIENT_LIKE_CYGWIN"

两种方法我都试过了——效果很好。

我使用第二个,因为我在我的 PC 上使用 git 分布式工具作为主要 ssh 代理。如果您的 PC 上没有 ssh 替代方案,第一个选项是合适的。

备注:

  • 有时,根据解析器,ini 文件中的路径会使用字符转义进行解析,因此 \ 可能会转义下一个符号。在这种情况下,路径应类似于 C:\\Program Files (x86)\\Git\\bin\\ssh.exe(带双斜杠)
  • 我的 %PATH% 变量中有 git\bin 目录,无需指定完整路径即可使用 ssh。在这种情况下,在 Mercurial 配置中你可以像这样使用:

    [ui]

    ssh = ssh

How do I prevent “No supported authentication methods available” error when using TortoiseHg?

Get/Run puttygen.exe ,单击生成,(无密码),然后关闭 window,保存公钥,保存 PrivKey。复制所有关键文本(否则您将不得不返回 puttygen)并将其粘贴到 BitBucket 网页上的 Account/Profile/Settings/Security/SSHKeys 区域。 (右键单击)系统托盘中的 pageant.exe 图标 - 单击“添加密钥”。 退出选美并重新加载它只是为了确保。退出乌龟并重新加载它只是为了确保。很高兴。