SSH Keys Suddenly Refused to Connect

Strangely, my Debian system (running on WSL) suddenly refused to connect to both Gitlab and GitHub using my SSH keys. Everything was fine when I last used it a couple of weeks ago. But now running the command ssh -Tv [email protected] returns a "Connection timed out" error.

img

And I didn't see the same issue using the same SSH keys on a Ubuntu system (also running on WSL) and Git Bash on Windows. So, there is no issues with my SSH keys.

I was very close to re-building my Debian system until I saw this Stack Overflow answer. According to this Stack Overflow answer, which also has a link to one of GitHub's Troubleshooting SSH article, most probably the firewall has refused the SSH connection.

Sometimes, firewalls refuse to allow SSH connections entirely. If using HTTPS cloning with credential caching is not an option, you can attempt to clone using an SSH connection made over the HTTPS port. Most firewall rules should allow this, but proxy servers may interfere

A quick workaround is to change the hostname and port i.e. use port 443 and hostname ssh.github.com instead. To quickly test this, we can use the ssh command below.

img

The final touch would be to add the hostname and port to the ~/.ssh/config file.

Host github.com
  Hostname ssh.github.com
    Port 443

Host gitlab.com
  Hostname altssh.gitlab.com
    Port 443

With this in my SSH configuration file, I can now connect happily to GitHub and Gitlab.

img

Share this: