【问题标题】:Git clone via SSH in Cygwin does not prompt for password, errors out instead在 Cygwin 中通过 SSH 进行的 Git 克隆不提示输入密码,而是出现错误
【发布时间】:2018-04-30 18:47:45
【问题描述】:

我正在尝试使用以下命令通过 SSH 从受密码保护的无头服务器进行 Git 克隆。我正在将 Cygwin 与 OpenSSH 一起使用。我可以使用 Cygwin 对服务器进行交互式 SSH,而不会出现问题。该问题仅出现在 Cygwin 中,而不会出现在 Windows 命令提示符中。

git clone ssh://username@server.edu:path/to/repo/reponame

我没有收到任何密码提示。我收到以下错误:

Cloning into 'reponame'...
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
Permission denied, please try again.
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
Permission denied, please try again.
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
username@server.edu: Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我假设这是由 SSH 和 Cygwin 设置引起的。

到目前为止我尝试过的不成功的“解决方案”是:

  1. 使用形式的命令

    git clone ssh://username:password@server.edu:path/to/repo/reponame

  2. 进入

    取消设置 GIT_ASKPASS 取消设置 SSH_ASKPASS

并重试克隆。

  1. 在我的本地计算机上打开 x 转发服务器并重试克隆。

最终奏效的解决方案是打开一个 Windows 命令提示符并使用它而不是 Cygwin 终端。 Cygwin 中的哪些设置可能导致该问题,我该如何解决?

【问题讨论】:

  • 您可以使用 Cygwin 或仅使用命令提示符进行 ssh 吗?
  • 我可以使用 Cygwin 进行 ssh。我将在正文中澄清这一点。
  • 可能它无法将 cygwin 终端识别为交互式。
  • 您是否从“本机”Cygwin 终端运行 git clone 目录?还是您使用某种形式的 X 终端?我无法准确复制您在 Cygwin 中看到的内容,并且只能强制 ssh-askpass 运行,如果我跳过箍强制它在没有伪终端的情况下运行。

标签: git ssh cygwin


【解决方案1】:

首先,考虑使用 CMD(或 git bash)中的 Git for Windows:您根本不需要 Cygwin。这意味着使用简化的 PATH 从 git bash 测试您的 ssh。

set G=c:\path\to\latest\git
set PATH=%G%\bin;%G%\usr\bin;%G%\mingw64\bin
set PATH=%PATH%;C:\windows\system32;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\

我知道它已经在 CMD 中工作,但是使用简化的 PATH 通常是一种很好的做法,可以验证它是否可以满足我们的需要(而不是因为其他一些程序 PATH)

其次,在 Cygwin 中(如果必须使用它),至少尝试 ssh -Tv ssh://username@server.edu 以查看相同的错误是否仍然存在,以及详细输出是否有更多线索。
检查 $HOME 值 (echo $HOME) 以查看 $HOME/.ssh 是否有您的私有/公共 (id_rsa/id_rsa.pub) 密钥。

【讨论】:

  • 我更喜欢使用 Cygwin,因为 Cygwin 是我正常工作流程的一部分,而 CMD 不是。如原始问题所述,我可以从 Cygwin 进行 SSH 登录。只有当我尝试 git clone 时才会出现问题。正如原始问题中所述,我没有设置 SSH 密钥。通常,当我对服务器进行 SSH 登录时,服务器会提示我输入密码。但是,当我尝试从服务器执行 git clone 时,我没有得到密码提示。
  • @dfghbvcx 你会从 Git for Windows 获得与 git bash 完全相同的工作流程:比 cygwin 更新。相同的 Linux 命令。
  • 我将 Cygwin 用于所有其他终端任务。我宁愿只使用一种终端,而不是为 Git 打开不同的终端。
  • @dfghbvcx 完全正确:打开 git bash 一次,然后在其中执行所有其他任务,而不仅仅是 git 操作。
  • +1 建议ssh。它将服务器添加到已知主机,然后在此事件之后,Git 像魅力一样连接!
【解决方案2】:

这是因为你在 Cygwin 下设置了 DISPLAY 环境变量吗?从 SSH 手册页:

 SSH_ASKPASS           If ssh needs a passphrase, it will read the
                       passphrase from the current terminal if it was run
                       from a terminal.  If ssh does not have a terminal
                       associated with it but DISPLAY and SSH_ASKPASS are
                       set, it will execute the program specified by
                       SSH_ASKPASS and open an X11 window to read the
                       passphrase.  This is particularly useful when call‐
                       ing ssh from a .xsession or related script.  (Note
                       that on some machines it may be necessary to redi‐
                       rect the input from /dev/null to make this work.)

我刚刚快速玩过 Cygwin 和 Linux,我可以复制您看到的内容,但前提是 git clone 在没有伪终端的进程中运行。 (看来/usr/lib/ssh/ssh-askpassSSH_ASKPASS 的默认值,即使SSH_ASKPASS 未设置,ssh 也会使用它。)也就是说我无法完全复制你看到的内容——我的 Cygwin 命令行有伪终端和git clone 按预期提示输入密码。我只能将您看到的内容复制到我 ssh -T 到另一台机器上,然后运行 ​​git clone

如果你 unset DISPLAY 然后运行 ​​git clone,你可能会收到不同的错误消息 - ssh 将不再尝试使用 ssh-askpass 读取密码短语,但它仍然没有伪终端读哪个!

【讨论】:

    猜你喜欢
    • 2019-03-07
    • 1970-01-01
    • 2016-11-20
    • 2016-03-08
    • 2017-10-07
    • 2017-03-06
    • 2017-09-30
    • 1970-01-01
    • 2014-07-30
    相关资源
    最近更新 更多