Chakradar Raju
Chakradar Raju

Reputation: 2821

making git prompt for password in terminal

I'm using git for one of my projects. Whenever I try to push to remote repo, git prompts me for password using a X window, so if I try to ssh to the computer and push I also have to X forward to make the window appear in my screen.

Is it possible to make git prompt for password in the terminal itself?

Upvotes: 10

Views: 2700

Answers (2)

Florian Mertens
Florian Mertens

Reputation: 2448

@Screwtape is (at least partially) correct, in his answer. If you look at this page, it shows the same problem (amid a larger problem), but it also indicates how to go around this error.

Whilst you are SSH'ing into the computer where you would like to run the git command, try:

$ unset SSH_ASKPASS

This unsets the $SSH_ASKPASS environment variable. If you then run the git command that you wanted to run, it should work. It works in my windows putty terminal in which I am SSH'ing to a CentOS server. Note that this unset change is NOT permanent (maybe a good thing) and you need to re-unset this parameter next time you login, but it gets the job done if you want to run GIT scripts.

Why is this bug still there, despite it being reported more than two years ago? From this source, it seems that Windows never sets the DISPLAY environment variable, and therefore GIT wouldn't work properly if it does make this check. The functionality is therefore left out (apparently) and the quote left by @Screwtape is correctly copied, but not applied in reality.

Upvotes: 6

Screwtape
Screwtape

Reputation: 429

This is not a behaviour of git; you are pushing to a repo over SSH, and SSH is asking for your password. The ssh manpage says:

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.

Normally when you ssh to a remote host, ssh clears the DISPLAY variable to prevent exactly these kinds of problems, but it's possible you may have configured ssh to propagate more environment variables than the default configuration allows. In that case, make sure ssh does not copy the DISPLAY variable to the remote host (if you need X11 forwarding, ssh will create its own, new DISPLAY variable, it doesn't need your original one). That should prevent ssh-askpass from being launched on the server where you're running git.

Upvotes: 2

Related Questions