'Cannot connect to GitHub via SSH (But can connect to GitLab)

I've scoured the internet and found many people with similar problems, but my variant seems to be unique. The issue is I cannot connect to GitHub via ssh in order to push/pull (I'm on Windows 10).

If I run ssh -T [email protected]:

ssh: connect to host github.com port 22: Network is unreachable

If I run ssh -T -p 443 [email protected]:

Hi cjriches! You've successfully authenticated, but GitHub does not provide shell access.

Bizarrely, if I run ssh -T [email protected]:

Welcome to GitLab, @cjriches!

This, combined with the fact that I tried disabling Windows Firewall to no avail, seems to prove that it's not just port 22 that's the problem. For what it's worth, I can also SSH into other, completely non-git-related hosts. For some reason, it's GitHub specifically that refuses to connect. I've re-uploaded the public key just in case, so the problem definitely isn't there.

Has anybody got any ideas how on earth this could be happening?



Solution 1:[1]

I had the same issue. Solve it by disabling the Virus Safe and Child Safe in the "Manage my Web Safe settings" section in the virgin broadband account page.

Source: https://community.virginmedia.com/t5/Forum-Archive/GitHub-inaccesible-over-SSH/td-p/3816287

Solution 2:[2]

Check git config --show-origin -l to see if there is any setting (proxy or others) that might apply to github.com specifically.

And check your environment variables ('set' in a CMD in Windows), also to double-check if any of those variables might involves GitHub.

Solution 3:[3]

Thanks to the OP and the other answers. My solution was to edit my ~/.ssh/config file (on linux).

Host github.com
HostName 140.82.121.4
User git
AddKeysToAgent yes
# Linux does not recognise UseKeychain but Mac does
IgnoreUnknown UseKeychain 
UseKeychain yes
IdentityFile ~/.ssh/your_ssh_key_file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amadu Bah
Solution 2 VonC
Solution 3 KolaB