Bug Resolution: ssh: connect to host github.com port 22: Connection refused

Bug Description

  • Git version: 2.42.0.windows.2

  • Error: ssh: connect to host github.com port 22: Connection refused

I have been able to update and publish website content normally before, but today when I use hexo d to update my blog, I encountered an error as shown below:


Solution

First, you need to check whether the SSH key is correctly configured locally and in your Github account. If the SSH key is not configured correctly, you will encounter the following error when you use hexo d:

1
2
git@ssh.github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

You can find Deploy keys in your Github account, as shown below:

Use ssh-keygen -t rsa -C "your email" in Git Bash to generate an SSH key, and then add the contents of id_rsa.pub to the Deploy keys of your Github account.

If your SSH key is correctly configured, create a config file with the following content in the .ssh folder (C:\Users\your_user_name\.ssh):

1
2
3
Host github.com
Hostname ssh.github.com
Port 443

Like this:

Then enter the following code in Git Bash to test whether you can connect:

1
ssh -T git@github.com

If you see "You've successfully authenticated", it means the connection is successful, as shown in the following figure:

In addition, sometimes you will encounter the following error when using hexo d to update your website:

1
2
ssh: connect to host ssh.github.com port 443: Connection timed out
fatal: Could not read from remote repository.

In this situation, you can try to enter hexo d again, because this may just be caused by an unstable network connection.