git produces Gtk-WARNING: cannot open display

GitVersion ControlGithubSsh

Git Problem Overview


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://[email protected]/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 [email protected]: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?

Git Solutions


Solution 1 - Git

I have finally discovered a solution to the problem. As it was described here, I ran the following command in the terminal:

  unset SSH_ASKPASS

and then running git push origin master works the way it should. You can also add the line to your .bashrc file.

Solution 2 - Git

I recently dealt with this behavior on a RedHat 5 machine where our Git version was 1.7.4.1.

I didn't have a high degree of confidence that unset SSH_ASKPASS wouldn't have unintended consequences, so I wanted to see if there was another solution.

I couldn't tell for certain, but it seems that a patch for this problem was in the works around the same time that our version of Git had been published. So, it seemed to me that it was reasonable to hope that a more recent version would correct the behavior.

And indeed it did. Upgrading to the 1.8 branch of Git resolved the problem. The error message is still displayed for some odd reason, but you are correctly prompted for your password and allowed to continue.

Solution 3 - Git

None of these answers worked for me (ssh'ing via Cygwin on Windows 10 into a RHEL 6.8 server and trying to clone a github.com repo from the RHEL box) so what I did was clone via an SSH key rather than HTTPS username/password. e.g. I used [email protected]:MyUsername/myproject.git rather than the https url. I also appropriately uploaded my public key into Github. This method worked fine.

Note: Of the above solutions, I actually didn't try upgrading to the 1.8 branch of git

Solution 4 - Git

You can also try to login using ssh -Y to the remote server so the dialogue box can appear graphically.

Like the OP, logging in via ssh -X didn't work. When trying to push, the server simply repeated the same error message - (gnome-ssh-askpass:29241): Gtk-WARNING **: cannot open display: - as it did when logging via ssh with no X11 forwarding. This is slightly different behavior from what the OP reported when he tried ssh -X as his error message changed slightly from just using ssh.

However, for me, once logged in using ssh -Y: there was no error, the password dialogue box popped up, I typed the password in, and GitHub accepted the push.

As a forewarning, ssh -Y can open up security problems as you are treating the remote server as a trusted client (https://askubuntu.com/questions/35512/what-is-the-difference-between-ssh-y-trusted-x11-forwarding-and-ssh-x-u). So be careful when using it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn ManakView Question on Stackoverflow
Solution 1 - GitJohn ManakView Answer on Stackoverflow
Solution 2 - GiteikonomegaView Answer on Stackoverflow
Solution 3 - GitjohnsimerView Answer on Stackoverflow
Solution 4 - Gitdada_daveView Answer on Stackoverflow