13

How do I force the git-client to use the console/terminal only. When I ssh into my remote/headless linux computer and try to run:

git clone https://myname@bitbucket.org/xxx/xxx.git

git complains and gives me this error: (gnome-ssh-askpass:2769): Gtk-WARNING **: cannot open display:

I dont want to use a graphical interface nor ssh -X. I just want to configure the git-client to use the terminal only.

Im using CentOs and got the git-client with yum install git.

ehrhardt
  • 2,346
  • 1
  • 19
  • 13
  • Possible duplicate of ["git push" produces Gtk-WARNING](http://stackoverflow.com/questions/16077971/git-push-produces-gtk-warning) – Alberto Feb 12 '16 at 10:20

4 Answers4

26

You can disable gnome-ssh-askpass in the current session by unsetting the SSH_ASKPASS environment variable:

unset SSH_ASKPASS

You could probably add it in your .bashrc or .profile with a conditional check whether the user logged in using SSH. Something like:

[ -n "$SSH_CONNECTION" ] && unset SSH_ASKPASS

BTW, someone else has also complained about the git's behavior of invoking the SSH_ASKPASS program blindly without determining if it is a GUI session or not. If you read the full thread, it would explain it is not possible to use DISPLAY environment variable to detect this. Also there is no mention of whether that patch was accepted or not.

Tuxdude
  • 47,485
  • 15
  • 109
  • 110
  • could you elaborate a bit more on [ -n "$SSH_CONNECTION" ]?? what does the square bracket means?? My bash shell seems not to accept those. – Weishi Z Dec 18 '14 at 23:10
  • @WeishiZeng - The square brackets indicate a test expression. The command checks that if the current shell is running within a SSH session, and if so, unsets the SSH_ASKPASS environment variable. More info about test expressions here: http://linux.die.net/man/1/test – Tuxdude Dec 19 '14 at 00:46
5

Based on Tobu's answer, I ended up with this in my ~/.bashrc - I guess you'll want it in ~/.bash_profile if you are using git from an ssh session:

export GIT_ASKPASS=

which seems to prevent the annoying gnome-ssh-askpass dialogue, using the CLI password prompt.

Unsetting SSH_ASKPASS, which is the advice that seems most common, presumably could have some unintended side effects.

Sam
  • 557
  • 6
  • 20
3

You need to change your ssh-askpass command to something that is not using a UI (atm it is gnome-ssh-askpass as seen from the error message).

Femaref
  • 60,705
  • 7
  • 138
  • 176
2

Exporting

GIT_ASKPASS=true

will disable any prompting.

Starting with Git 2.3, you can use

GIT_TERMINAL_PROMPT=0

or write a short script that does echo quit=1 and use it for core.askpass.

Tobu
  • 24,771
  • 4
  • 91
  • 98
  • I use HTTPS not SSH. After much research "export GIT_ASKPASS=true" before a "git pull" is the only thing that worked for me. Upgrading to GIT 1.8 might work as well but this was not an option for me. – user1097111 Feb 07 '17 at 09:38