140

I've been working on my project remotely through the command line on a machine to which I don't have admin rights and after running git push origin master I get the following error message:

(gnome-ssh-askpass:29241): Gtk-WARNING **: cannot open display:

My .git/config file has the following contents:

    [core]
       repositoryformatversion = 0
       filemode = true
       bare = false
       logallrefupdates = true 
    [remote "origin"]
       fetch = +refs/heads/*:refs/remotes/origin/*
       url = https://username@github.com/username/repository.git 
    [branch "master"]
       remote = origin
       merge = refs/heads/master

I was getting the 403 error earlier. Following the comment here, I put my username before the @ sign in the remote url and since then, I've been getting the Gtk error.

When I login to the machine using ssh -X and try to push, I get the following error:

X11 connection rejected because of wrong authentication.
(gnome-ssh-askpass:31922): Gtk-WARNING **: cannot open display:localhost:10.0

If I change the url of the remote to git@github.com:username/repository.git, then the error is:

ssh: connect to host github.com port 22: Connection timed out
fatal: The remote end hung up unexpectedly

Do you know how to fix this?

4

4 回答 4

344

我终于找到了解决问题的方法。正如这里所描述,我在终端中运行了以下命令:

  unset SSH_ASKPASS

然后git push origin master以应有的方式运行。您还可以将该行添加到您的.bashrc文件中。

于 2013-04-19T12:19:52.567 回答
19

我最近在我们的 Git 版本为 1.7.4.1 的 RedHat 5 机器上处理了这种行为。

我没有高度的信心unset SSH_ASKPASS不会产生意想不到的后果,所以我想看看是否有其他解决方案。

我无法确定,但似乎在我们的 Git 版本发布的同时,针对这个问题的补丁正在开发中。因此,在我看来,希望更新的版本能够纠正这种行为是合理的。

确实如此。升级到 Git 的 1.8 分支解决了这个问题。 由于某些奇怪的原因,错误消息仍然显示,但系统会正确提示您输入密码并允许继续。

于 2014-01-20T19:25:29.967 回答
0

这些答案都不适合我(通过 Windows 10 上的 Cygwin SSH 到 RHEL 6.8 服务器并尝试从 RHEL 框中克隆 github.com 存储库)所以我所做的是通过 SSH 密钥而不是 HTTPS 用户名/密码。例如,我使用 git@github.com:MyUsername/myproject.git 而不是 https url。我还适当地将我的公钥上传到了 Github。这种方法效果很好。

注:以上解决方案中,我其实并没有尝试升级到 git 的 1.8 分支

于 2016-09-13T20:05:11.637 回答
0

您也可以尝试使用 ssh -Y 登录到远程服务器,以便以图形方式显示对话框。

与 OP 一样,通过 ssh -X 登录也不起作用。尝试推送时,服务器只是重复了相同的错误消息 -(gnome-ssh-askpass:29241): Gtk-WARNING **: cannot open display:就像在没有 X11 转发的情况下通过 ssh 登录时一样。这与 OP 在尝试 ssh -X 时报告的行为略有不同,因为他的错误消息与仅使用 ssh 略有不同。

但是,对我来说,一旦使用 ssh -Y: 登录没有错误,弹出密码对话框,我输入密码,GitHub 接受了推送。

作为预警, ssh -Y 可能会引发安全问题,因为您将远程服务器视为受信任的客户端(https://askubuntu.com/questions/35512/what-is-the-difference-between-ssh-y-受信任的 x11 转发和 ssh-xu)。所以使用的时候要小心。

于 2019-04-14T07:13:42.557 回答