Could someone help me figure out how to get git clone over ssh working in Windows Subsystem for Linux (WSL2) with Ubuntu version 20.04.1 LTS? Testing the ssh connection or attempting to clone a repo over ssh both fail with the error message “Received disconnect from 192.30.255.112 port 22:11: Bye Bye” and “fatal: Could not read from remote repository.”
Here are the commands I’m using:
- ssh -T git @github.com
- git clone git @github.com:bluesherpa/array_sort.git ./
Note: space between git and @ added so I can submit this post.
Performing the clone over HTTPS works:
- git clone https://github.com/bluesherpa/array_sort.git ./
I run these commands to setup SSH from within an Ubuntu bash terminal:
- rm -rf ~/.ssh
- pkill ssh-agent
- ssh-keygen -t rsa -C “”
- eval
ssh-agent -s
- ssh-add -D
- ssh-add ~/.ssh/id_rsa
I realize there are some extra steps there. I use pkill to stop the ssh-agent process and make sure that’s not causing problems, same with using “ssh-add -D” to make sure there are no certificates.
I copy the content of ~/.ssh/id_rsa.pub and add the corresponding SSH key in my GitHub account.
I try the testing the ssh connection and cloning a repo after everything is setup with no luck.
None of this works from Ubuntu under WSL2, but to cross-reference this, I removed ~/.ssh and killed the ssh-agent and tried everything from scratch using Git Bash - it works from there.
I tried checking which version of git is installed in Ubuntu. It was an old version, so I upgraded it so now git.exe from the Git Bash Windows installation and the Ubuntu git are the same version.
I tried using the version of git that comes with Git Bash under Ubuntu with the command:
- git.exe clone https://github.com/bluesherpa/array_sort.git ./
That works.
Basically, I can get everything working under Git Bash, but not Ubuntu and I’m not sure why. I even tried copying the .ssh directory from my home directory in Windows to my home directory in Ubuntu.
I tried uninstalling/reinstalling Git Bash and trying different options for the credential helper, including using the Git Credential Manager Core, the Git Credential Manager, and none. None of that made a difference, tho I found it interesting that running ‘git clone’ under Ubuntu would trigger a popup menu from Git Credential Manager Core, which doesn’t work and does a fail over to basic authentication at the command prompt.
I have tried all of this using an Ubuntu Bash Shell from the Windows Start menu, an Ubuntu Bash Shell from Windows Terminal, and an Ubuntu Bash Shell “Terminal” from Visual Code.
Another thing I tried was cross-referencing this with using a phrase and not using a phrase when generating the keys.
Finally… I notice that when I try this from Git Bash, I get prompted to create a new entry in known_hosts. This does not happen when I try with Git in Ubuntu. I tried just copying the known_hosts file to ~/.ssh but that didn’t seem to help.
I’m not sure if this information is being cached anywhere, but GitHub seems respond pretty quickly every time I delete and recreate the keys from within Git Bash.
Here are the documents I’ve been trying to follow:
- https: // docs.github. com /en/free-pro-team@latest/github/authenticating-to-github/connecting-to-github-with-ssh
- https: // docs.microsoft. com /en-us/windows/wsl/tutorials/wsl-git
Sorry if this is too much detail, but I really do appreciate your help.
-Ed