Cygwin/Git Bizarre Terminal Issue
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:
- Install win-ssh-askpass application by unpacking and copying to C:\
- 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)
- 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. - 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 :)
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)
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