kex_exchange_identification: Connection closed by remote host ... How do I resolve this error

emil@DESKTOP-1I1B1NM:~$ git clone [email protected]:EmilYoung2004/git_test.git
Cloning into 'git_test'...
kex_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository
Please make sure you have the correct access rights    
and the repository exists.

emil@DESKTOP-1I1B1NM:~$ ssh -T [email protected] kex_exchange_identification: Connection closed by remote host

As you can see I am trying to connect to github from the Ubuntu 20.04 app from Microsoft Store This is really annoying as I can't carry on with what I'm doing until this is sorted Is there something I can change to prevent this error from happening?

Something tells me there's an error connecting to Github itself but I wouldn't know

I'm learning so don't make the answers too complicated

Thank's in advance


Please make sure you have the correct access rights

That's the key part of the error. Basically, github is refusing access to that repository via SSH, because you're not authenticating with a key that's either on your account or on that repository.

Within your Ubuntu shell, check if you have SSH keys generated at all with ls -la ~/.ssh. You should probably see a couple of files in there named id_rsa and id_rsa.pub if you have keys. If not, that's fine, you can generate them with ssh-keygen and follow the prompts (accepting the defaults should be fine).

Now that you have keys, you're going to want to add the public key to your github account. A little side note here, id_rsa is your private key. Keep this private. Never give it to anyone, never share it, post it online etc etc. id_rsa.pub is your public key. This one is the one that you put on other devices you want to authenticate into, in this case Github. There's no problem giving the public key to other people/services.

Output your public key with cat id_rsa.pub and copy the text it outputs. Then go to Github in your browser, ensure you're logged in, click your user icon up the top right, and go to settings.On the left menu, you'll see SSH and GPG Keys. Click that (or just go https://github.com/settings/keys if you're having problems). Click New SSH Key, put a name that identifies the computer your key is from in the Title, and paste the public key in the Key field. Hit Add SSH Key and you're done.

You should now have access to clone via SSH, so try the git clone again and see how it goes.


NB: you can also clone via HTTPS etc which will get you around this given your repo is public, however it's better to setup key auth for SSH and go down this path in the long run.