Cygwin/Git Bizarre Terminal Issue

16

11

Alright, this is weird. First off, this is mintty running on up-to-date cygwin, with git pulled from cygwin's setup.exe. I am running zsh.

$ git clone https://<user>@<domain>/<repository>/ ~/src/project/dev
Initialized empty Git repository in /cygdrive/c/src/project/dev/.git/
Password: <actual password in plain text appears>
# Nothing happens...
^C
$ <password text that I just typed>
zsh: command not found: <same password text>

What is going on here? Is this a terminal problem, a shell problem, a git problem, or a cygwin problem?

Update: Yes, I'm running the Cygwin git version, not the Windows version:

$ which git
/usr/bin/git
$ git --version
git version 1.7.1
$ /cygdrive/c/Program\ Files\ \(x86\)/Git/bin/git.exe --version
git version 1.7.0.2.msysgit.0

emptyset

Posted 2010-06-30T16:31:07.480

Reputation: 421

1I'm guessing a terminal problem. The fact that your password appears suggests that the terminal isn't properly being put into silent mode (where it doesn't show the characters you type), and the fact that the password text appears again after you hit ^C suggests that the characters aren't getting sent to stdin of the git process. But I don't know what the specific problem might be. – David Z – 2010-06-30T17:09:57.200

Thanks for the clue - I came across this: http://code.google.com/p/mintty/issues/detail?id=56 - but there's no way to put git in interactive mode like the python executable...

– emptyset – 2010-06-30T18:09:24.810

1Are you sure you're invoking Cygwin's version of git? Mintty issue 56 only applies to native Windows programs. – ak2 – 2010-07-01T05:15:44.007

Did you find a solution to this problem? – pauldoo – 2010-12-07T12:38:13.260

Answers

9

OK, I think I've found a definite solution.

The problem is that, regardless of the terminal used (puttycyg, mintty, cmd.exe), Git by default, in the absence of better configured alternatives, tries to use a "simple password prompt" (as you can read in the description of core.askpass config option).

The simple password prompt apparently only works on real UNIX, but not on Cygwin.

The solution is to install an SSH_ASKPASS compatible program for Windows and configure Git to use it.

What I did was:

  1. Install win-ssh-askpass application by unpacking and copying to C:\
  2. Download and install the Borland Delphi 5 runtime required by win-ssh-askpass (hard to come by nowadays, but found one on http://www.satsignal.eu/software/runtime.html)
  3. Configure Git to obtain passwords using win-ssh-askpass: git config --global core.askpass "C:/win_ssh_askpass.exe". Note that the EXE file has underscores in its name, not minus signs.
  4. Remember to always place your login in the URL (https://<user>@<domain>/<repository>). Otherwise, Git will ask for the login before asking for the password, using the same askpass utility. You may unknowingly input your password as the login, which will be sent to the webserwer and logged in its access log as plain text!

Now Git asks for the password using an elegant GUI window and works regardless of the terminal used :)

Aleksander Adamowski

Posted 2010-06-30T16:31:07.480

Reputation: 255

1I just ran the following and it pops a gui: git config --global core.askpass "git-gui--askpass" clone – Derek Greer – 2015-02-24T22:41:59.150

thanks, run randomly, but runs :) I don't know why git don't run as expected. subversion do it fine. – corretge – 2012-02-20T16:59:00.107

7

I've experienced the same issue - however in my case I am SSH'd in the Cygwin server so obviously a Win32 GUI askpass won't work.

Instead, I wrote this simple script to do the askpass. I though it could be used from regular prompts as well by getting the tty device from /bin/tty.exe but that didn't work for an unknown reason (feel free to tty yourself or look for another solution to get the tty, maybe I just got it wrong somehow).

/bin/askpass.sh:

#!/bin/bash

TTY=$SSH_TTY
[ -c "$TTY" -a -r "$TTY" -a -w "$TTY" ] \
  || { echo "Failed to open device \`$TTY'!"; exit 1; }
exec <$TTY

echo -n "$@" >$TTY
read -s P
echo >$TTY

echo $P

Make sure this script is executable and use it as your git's core.askpass setting. Since this script relies on the $SSH_TTY variable it will normally only work from SSH. You could however set $SSH_TTY in .bashrc or .bash_profile if unset; this way it should work even from a console. The following line in your rc script should do it:

[ -z "$SSH_TTY" ] && export SSH_TTY=$(/bin/tty.exe)

Thomas Guyot-Sionnest

Posted 2010-06-30T16:31:07.480

Reputation: 71

I can confirm this solution, works very well. – schlamar – 2012-03-07T13:04:14.303

This worked pretty well for me too. However, I had to add a redirect (1>&2) on that "Failed to open ..." message in order for it to be visible. – Eric – 2012-04-03T18:34:36.323

2

solutions above do not work for me, but I found another one.

you have to run ssh agent

just add to ~/.bashrc and restart console

SSH_ENV=$HOME/.ssh/environment



# start the ssh-agent

function start_agent {

    echo "Initializing new SSH agent..."

    # spawn ssh-agent

    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"

    echo succeeded

    chmod 600 "${SSH_ENV}"

    . "${SSH_ENV}" > /dev/null

    /usr/bin/ssh-add

}



if [ -f "${SSH_ENV}" ]; then

     . "${SSH_ENV}" > /dev/null

     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {

        start_agent;

    }

else

    start_agent;

fi

P.S. Chrome and Opera use linebreak which isn't compatible with bash - just use another browser for copy paste

Aloy

Posted 2010-06-30T16:31:07.480

Reputation: 21

1

Question was answered already... I just would like to add how I fixed:

Checking Windows Git Bash, I could see that git set following SSH_ASKPASS

$ echo $SSH_ASKPASS
/mingw64/libexec/git-core/git-gui--askpass

So, on Cygwin, I added same variable to .bashrc

# Unconditionally export SSH_ASKPASS
export SSH_ASKPASS="/mingw64/libexec/git-core/git-gui--askpass"

or

# export SSH_ASKPASS only if git is installed
hash git 2>/dev/null && export SSH_ASKPASS="/mingw64/libexec/git-core/git-gui--askpass"

Doing this, git opens the SSH_ASKPASS from Git... I did not had to install any additional SW or create any additional script.

Hope this can help!

W0rmH0le

Posted 2010-06-30T16:31:07.480

Reputation: 31

1

It's possible you have a metacharacter, such as &, in the URL. This would cause git to run in the background, and on a Unix system it would be stopped as soon as it tried to read from stdin. A ; would also terminate the command partway through the line, and the Ctrl-C would cause the rest of the line (a separate command) to be aborted.

It's interesting that git initializes the repo in /cygdrive/c/src/project/dev/.git/ even though you told it to use ~/src/project/dev (unless you have your home directory in a strange place). This would suggest that the git command is not seeing the rest of the command line, which is what would happen if there was a stray & or ; in the URL.

(I've had this problem lots of times with wget, although not with git.)

Try a git clone from a different repo, or using a different transport from the same repo, to see if git is messed up generally or just for this repo. You could also try putting single quotes around the URL.

Neil Mayhew

Posted 2010-06-30T16:31:07.480

Reputation: 776

~/src is a symlink to /cygdrive/c/src (C:\src). There's no & in the URL. I'll try to clone a public git repository, but generally those won't have a password... – emptyset – 2010-07-06T13:58:29.630

1

Take a look at the following issue - I'm fairly certain now it's just a limitation of mintty and interoperability with Windows.

Issue 56 - mintty

I've also had problems running mysql and such from mintty - so, the answer is that it's a terminal emulation problem.

emptyset

Posted 2010-06-30T16:31:07.480

Reputation: 421

0

Years ago I remember having some problems with Cygwin's CVS authentication... it was to do with whether you installed Cygwin with the DOS or Unix style line endings (CRLF vs just LF); it's one of the options on the installer dialog. If you picked the wrong one (I think DOS was the one which worked) the password would end up mangled or with a spurious character or something.

Anyway, might be worth trying the other option.

timday

Posted 2010-06-30T16:31:07.480

Reputation: 762

0

I have the same problem, and, contrary to this thread, the problem occurs with Cygwin GIT in all possible terminals - puttycyg, mintty and the classical Windows cmd.exe.

I'm still looking for a proper solution, but there's a workaround - although it's very insecure, you can try placing the password in repository URL, e.g.:

git clone https://<user>:<password>@<domain>/<repository>/

Does the workaround work for you?

Aleksander Adamowski

Posted 2010-06-30T16:31:07.480

Reputation: 255

0

Just a refinement on comment #2

There's a cygwin ssh-ask-pass (unofficial) here

Just download the tar.bz2 and unpack into your cygwin folder. It works without installing borland delphi runtime.

Raghu

Posted 2010-06-30T16:31:07.480

Reputation: 123

0

If it's a repository you use often, the easiest thing may be to create a ~/.netrc file with

machine git.example.com
login yourlogin
password your password

Obviously, you should set appropriately draconian permissions on the file.

Carson Chittom

Posted 2010-06-30T16:31:07.480

Reputation: 51

Why not just use ssh as a transport? – vonbrand – 2015-10-09T21:55:56.830