1

I am trying to use the following command to do a Git clone via SSH from a password-protected headless server. I am using Cygwin with OpenSSH. I can do an interactive SSH to the server without issues using Cygwin. The issue only occurs in Cygwin and not in the Windows Command Prompt.

git clone ssh://username@server.edu:path/to/repo/reponame

I do not get any sort of password prompt. I get the following error:

Cloning into 'reponame'...
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
Permission denied, please try again.
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
Permission denied, please try again.
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
username@server.edu: Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I am assuming this is caused by SSH and the Cygwin settings.

Unsuccessful "solutions" I have tried so far are:

  1. Using a command of the form

    git clone ssh://username:password@server.edu:path/to/repo/reponame

  2. Entering

    unset GIT_ASKPASS unset SSH_ASKPASS

and retrying the clone.

  1. Opening an x-forwarding server on my local machine and retrying the clone.

The solution that finally worked was opening up a Windows Command Prompt and using that instead of a Cygwin terminal. What setting in Cygwin could have caused the problem, and how do I fix it?

dfghbvcx
  • 11
  • 3
  • Can you ssh using Cygwin or just command prompt? – PrasadK Apr 28 '18 at 05:34
  • I can ssh using Cygwin. I will clarify that in the body text. – dfghbvcx Apr 28 '18 at 05:43
  • Probably it does not recognize the cygwin terminal as interactive. – max630 Apr 30 '18 at 07:15
  • Are you running the git clone directory from the "native" Cygwin terminal? Or are you using some form of X terminal? I'm having trouble replicating exactly what you see in Cygwin, and can only force ssh-askpass to run if I jump through hoops to force it run without a pseudoterminal. – Jon Apr 30 '18 at 10:50

2 Answers2

2

First, consider using Git for Windows from a CMD (or a git bash): you should not need Cygwin at all. That means test your ssh from a git bash, using a simplified PATH.

set G=c:\path\to\latest\git
set PATH=%G%\bin;%G%\usr\bin;%G%\mingw64\bin
set PATH=%PATH%;C:\windows\system32;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\

I understand it is already working in a CMD, but using a simplified PATH is generally a good practice to validate that it is working with what we need (and not because of some other program PATH)

Second, in Cygwin (if you must use it), try at least an ssh -Tv ssh://username@server.edu to see if the same error persists, and if the verbose output has any more clues.
Check the $HOME value (echo $HOME) to see if $HOME/.ssh does have your private/public (id_rsa/id_rsa.pub) keys.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I do prefer to use Cygwin, because Cygwin is part of my normal workflow, while CMD is not. As stated in the original question, I can do an SSH login from Cygwin. The problem only arises when I attempt the git clone. As also stated in the original question, I do not have SSH keys set up. Usually, when I do an SSH login to the server, the server prompt me for a password. However, when I attempt a git clone from the server, I am not given a password prompt. – dfghbvcx Apr 28 '18 at 05:56
  • @dfghbvcx You would get the very same workflow with git bash from Git for Windows: more recent than cygwin. Same Linux commands. – VonC Apr 28 '18 at 05:57
  • I use Cygwin for all other terminal tasks. I would prefer to only use one type of terminal, rather than open a different terminal for Git. – dfghbvcx Apr 28 '18 at 05:59
  • @dfghbvcx Exactly: open git bash once, and do all your other tasks in it, not just git operations. – VonC Apr 28 '18 at 06:01
  • +1 for suggesting `ssh`. It adds the server to known hosts, and followed by this event, Git connects like a charm! – Martin Mar 18 '19 at 00:23
  • @Martin Regarding ssh, beware of Git 2.19+: the key format has changed: https://stackoverflow.com/a/53645530/6309 – VonC Mar 18 '19 at 00:32
0

Is this is because you have the DISPLAY environment variable set under Cygwin? From the SSH man page:

 SSH_ASKPASS           If ssh needs a passphrase, it will read the
                       passphrase from the current terminal if it was run
                       from a terminal.  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.  This is particularly useful when call‐
                       ing ssh from a .xsession or related script.  (Note
                       that on some machines it may be necessary to redi‐
                       rect the input from /dev/null to make this work.)

I've just had a quick play with Cygwin and Linux, and I can replicate what you see, but only if the git clone runs in a process without a pseudoterminal. (It appears that /usr/lib/ssh/ssh-askpass is the default for SSH_ASKPASS, and ssh will use it even if SSH_ASKPASS isn't set.) That said I can't replicate exactly what you see - my Cygwin command line has pseudoterminal and the git clone prompts for a password as expected. I can only replicate what you see if I ssh -T into another machine and then run the git clone.

If you unset DISPLAY then run git clone, you'll probably get a different error message - ssh will no longer be trying to use ssh-askpass to read a pass phrase, but it still won't have a pseudoterminal from which to read one!

Jon
  • 3,573
  • 2
  • 17
  • 24