228

I'm attempting to clone a repo from my BitBucket account to my Windows 10 laptop (running GitBash). I've completed all of the steps necessary to connect (set up my SSH key, verified by successfully SSHing [email protected], etc). However, whenever I attempt to clone a repo, the prompt continually hangs up after confirming that I want to cache Bitbucket's key.

User@Laptop MINGW64 /C/Repos
$ git clone [email protected]:mygbid/test.git
Cloning into 'test'...
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) y

No files are cloned, and the result is an empty repo. Trying to initiate a git pull origin master from this repo also asks to cache the key, then hangs with no feedback. Despite not asking for the key to be cached when I do a test SSH, git operations always ask for the key every time before failing.

With no error messages to work with, I'm really at a loss as to what is wrong. I've tried multiple repos, including very small ones, with no success at all.

10 Answers 10

271

I had this problem when cloning a repo on Windows 10 too.

I got around it by using the Putty GUI to SSH to the server in question (in your case: bitbucket.org) then clicked 'Yes' when the prompt asks if you want to save the server key to the cache. Running the clone command again then worked for me!

7
  • 34
    This didn't directly fix it for me, but it lead me to realize that the problem was related to GitBash using Putty for ssh authentication instead of OpenSSH. When I deleted the GIT_SSH system variable and reset GitBash everything works fine. Thanks! Oct 30, 2015 at 19:58
  • 4
    Using putty to add github key in cache worked for me
    – oak
    Dec 14, 2015 at 13:25
  • 4
    This worked for me on Win 7 using the command console. I wish somebody could tell me why this happened rather than just a workaround.
    – soulsabr
    Feb 29, 2016 at 21:11
  • 2
    can anyone tell how to do above said solution Jan 6, 2019 at 9:54
  • 5
    @Shreyan Mehta just open putty, under host name paste [email protected] (or whatever host you are using). Be sure to select connection type of SSH. Port number should be 22. Also be sure to have the ssh key loaded into pageant before launching this. Jul 11, 2019 at 19:05
165
  1. Open Putty
  2. Type in the Host Name (like bitbucket.org)
  3. Click Open
  4. Click yes in the popup to cache the host key
  5. Close Putty
8
  • I had the same problem. Looking at the output from git, it seems like git is failing to cache the host key (probably a bug). So you have to do it using the PuTTY GUI. Jul 21, 2016 at 20:50
  • I tried all steps but when I select either 'y' or 'n' nothing happeds Git Bash does nothing Aug 18, 2016 at 20:21
  • Did you type the right host name in step 2? Did you try restarting Git Bash? Aug 18, 2016 at 20:23
  • 2
    How is this any different than the accepted answer?
    – zb226
    Feb 2, 2017 at 14:33
  • 1
    I up voted this answer as it provides steps. I don't like how it is a workaround (you have to repeat this for every SSH server you connect) just like the accepted answer.
    – ShooShoSha
    Jun 22, 2017 at 19:59
65

I managed to get it working by running plink directly, after pageant is running use the plink command directly - plink.exe -agent -v [email protected] then after this git works without hanging.

6
  • 8
    Nice solution ! This should have marked as an answer
    – ZenithS
    Nov 8, 2019 at 9:05
  • This is the best answer.
    – Brian Lacy
    Mar 4, 2020 at 17:15
  • I think this is not a workaround and this is the right solution
    – kaushik
    Oct 18, 2020 at 13:07
  • If you're having this problem with github, typing exactly that command at a dos prompt while pageant is running with your key solves this problem. I agree this is the best answer! Nov 2, 2020 at 21:35
  • This did the trick. The value from the registry has a different format so you should know it too. I'm having issues with Tortoise GIT's dialog box hanging on this and though I tried to push via windows command line it didn't work as well. Nice solution indeed! Jan 2, 2021 at 9:21
32

To do this from powershell open a powershell window and paste in the following:

echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh [email protected]
echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh [email protected]
echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh [email protected]

or with PuTTY standalone version:

echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh [email protected]
echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh [email protected]
echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh [email protected]

Also worth knowing is that putty stores known hosts under a registry key:

HKEY_CURRENT_USER\SoftWare\SimonTatham\PuTTY\SshHostKeys

To shortcut the above you could put the following in a .reg file and run it:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\SimonTatham\PuTTY\SshHostKeys]
"rsa2@22:github.com"="0x23,0xab603b8511a67679bdb540db3bd2034b004ae936d06be3d760f08fcbaadb4eb4edc3b3c791c70aae9a74c95869e4774421c2abea92e554305f38b5fd414b3208e574c337e320936518462c7652c98b31e16e7da6523bd200742a6444d83fcd5e1732d03673c7b7811555487b55f0c4494f3829ece60f94255a95cb9af537d7fc8c7fe49ef318474ef2920992052265b0a06ea66d4a167fd9f3a48a1a4a307ec1eaaa5149a969a6ac5d56a5ef627e517d81fb644f5b745c4f478ecd082a9492f744aad326f76c8c4dc9100bc6ab79461d2657cb6f06dec92e6b64a6562ff0e32084ea06ce0ea9d35a583bfb00bad38c9d19703c549892e5aa78dc95e250514069"
"rsa2@22:gist.github.com"="0x23,0xab603b8511a67679bdb540db3bd2034b004ae936d06be3d760f08fcbaadb4eb4edc3b3c791c70aae9a74c95869e4774421c2abea92e554305f38b5fd414b3208e574c337e320936518462c7652c98b31e16e7da6523bd200742a6444d83fcd5e1732d03673c7b7811555487b55f0c4494f3829ece60f94255a95cb9af537d7fc8c7fe49ef318474ef2920992052265b0a06ea66d4a167fd9f3a48a1a4a307ec1eaaa5149a969a6ac5d56a5ef627e517d81fb644f5b745c4f478ecd082a9492f744aad326f76c8c4dc9100bc6ab79461d2657cb6f06dec92e6b64a6562ff0e32084ea06ce0ea9d35a583bfb00bad38c9d19703c549892e5aa78dc95e250514069"
"rsa2@22:bitbucket.org"="0x23,0xb9b88df3578371a7eb80c78bcda14fb30da436f11ca932a5fd5a8b6adfcc681df7a59cb4cb7ac966d9eac11daa38ebdbc0a6582a210ed4ee95a8d101c4abc925e942ab47535d64f9a5b3b68035c2ea1e900d709a1e8ea938718f532f9805a190446b92bac3040126225ae9d8374bc2008f106979d631734c7453f78c70091f4783b288869cb3c1941a784cd9baad823be27333833dc1f488a45b85952be75cf0a64965662302e3915378dcd5cfcd3ec903d804a29dff2fdf19df5deba4534b09e4dea6e44f152e339b3c43be98ddadfc56533192e216a3d673f00b4aa9cc9e7870acd8b6adb7e0feb77f2292fc2dede94819def3eb1e785541a06ab31ccf725f"

putty-hosts.reg gist

3
  • 2
    See also earlier question and answer about this aspect of plink: serverfault.com/questions/420526/… Mar 24, 2017 at 14:07
  • 3
    FATAL ERROR: Disconnected: No supported authentication methods available (server sent: publickey)
    – Azimuth
    Mar 16, 2018 at 10:30
  • In the case that your remote operates on a port other than 22, you need to run plink with the port by passing it a -P <port> argument.
    – PitaJ
    Jul 9, 2019 at 18:24
6

To workaround this problem I configured GitBash to use plink with -batch option. The option disables all prompts - the plink will terminate without hanging and won't add any key fingerprint to cache.

To add -batch parameter to plink command executed by GitBash you can set a git config option:

git config --global core.sshCommand "plink -batch"

Or set GIT_SSH_COMMAND environment variable.

The output when you cloning a repo from unknown host will be similar to this:

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
Connection abandoned.
fatal: Could not read from remote repository.

After this message you can add a key to cache with command:

echo y | plink [email protected]

REMARK: Please check if plink is in your PATH. Alternatively use UNIX-like path in the GitBash config option, e.g.:

/c/Program\ Files/PuTTY/plink.exe -batch
2
  • 1
    HI i get this message: FATAL ERROR: Disconnected: No supported authentication methods available (server sent: publickey)
    – pungggi
    Aug 10, 2018 at 10:31
  • @pungggi, if you manage SSH keys in GPG then this can mean that gpg-agent is not started. Run gpg-connect-agent /bye beforehand. Oct 5, 2021 at 22:28
5

Even after performing the workaround mentioned in other answers, you may encounter an error like:

FATAL ERROR: Disconnected: No supported authentication methods available (server sent: publickey)

To solve both problems at once, change git bash to use SSH instead of PuTTY by adding the following to your ~/.profile file (C:\Users\<Username>\.profile). If you don't already have this file, then create a new file with this line.

GIT_SSH="/usr/bin/ssh.exe"

Then open a new git bash window and try your git clone or git pull again.

Note that this may require you to create an SSH key if you don't already have one. To do this, follow the instructions on the Bitbucket site.

See this SO question for related info.

2

In your git bash shell, check for existence of GIT_SSH:
echo $GIT<tab><tab>
If it exists and is set to putty, execute:
unset GIT_SSH
You'll probably want to put this into one of the git bash startup scripts.
This is NOT a universal solution. It worked in our particular case.

4
  • what/where is a 'git bash startup script'? I'm only familiar with real linux.
    – Jeff K
    Nov 13, 2019 at 19:50
  • There are multiple start up scripts. Some are located in the /etc directory; others can be in your home directory. Which start up scripts are executed depend on command line options to your shell (interactive vs login). These are relevant regardless of the OS the shell runs on top of. Nov 15, 2019 at 17:48
  • Windows has no '/etc' directory.
    – Jeff K
    Nov 20, 2019 at 2:21
  • Bash shells that run under Windows do. They are usually mapped to someplace off the shell's base (or install) directory. Take a look a git bash and Cygwin bash. Remember, these are shells that look like and operate a lot like a shell on a linux system. Nov 20, 2019 at 14:15
0

It sounds a bit silly, but after trying all of the above, I decided to reinstall Git Bash with default options and it worked.

0
0

If you use KiTTY (instead of PuTTY), it has -auto-store-sshkey argument.

So, you can set GIT_SSH_COMMAND (or git config --global core.sshCommand) to something like c:/KiTTY/klink.exe -auto-store-sshkey.

The output still contains information about new key and the question, but it doesn't wait for the answer:

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's ssh-ed25519 key fingerprint is:
ssh-ed25519 255 2e:65:6a:c8:cf:bf:b2:8b:9a:bd:6d:9f:11:5c:12:16
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)
Autostore key is on
0

Default SSH port to connect to is 7999

1
  • "Any answer that gets the asker going in the right direction is helpful, but do try to mention any limitations, assumptions or simplifications in your answer. Brevity is acceptable, but fuller explanations are better." - check How do I write a good answer. Please provide some explanations on how this answer's the OP's question.
    – Kuro Neko
    May 31, 2022 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.