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

??作者主页:?杰森的博客
??本文摘要解决 GitHub 报错:ssh: connect to host github.com port 22: Connection refused
??如果本文帮助到您,还请各位小伙伴?点赞➕收藏⭐➕评论?支持杰森呀✌️

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

报错信息:

$ git clone git@github.com:appletdevelop/full-stack.git
Cloning into ‘full-stack’...
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

方案一

日志:

$ ssh -vT git@github.com
OpenSSH_9.0p1, OpenSSL 1.1.1o  5 July 2022
debug1: Reading configuration data /c/Users/jason/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [::1] port 22.
debug1: connect to address ::1 port 22: Connection refused
debug1: Connecting to github.com [127.0.0.1] port 22.
debug1: connect to address 127.0.0.1 port 22: Connection refused
ssh: connect to host github.com port 22: Connection refused

解决:

140.82.112.4 github.com
# Refreshing DNS configurations
$ ipconfig /flushdns

方案二

方案:

$ vim ~/.ssh/config
# Add the following configuration information
Host github.com
  Hostname ssh.github.com
  Port 443

测试访问是否成功,通常不出意外的话意外就来了……

$ ssh -T git@github.com
The authenticity of host[ssh.github.com]:443([unknown ip address]:443)’ can’t be established.
xxx key fingerprint is xxx:xxx.
This host key is known by the following other names/addresses:
    # Delete the RSA information in line 8
    ~/.ssh/known_hosts:8: github.com
Host key verification failed.

这与 ssh 的运行机制有关,找到 known_hosts 文件中对应 ipRSA 并删除便可解决。

再次测试,看到以下信息则表示访问成功

$ ssh -T git@github.com
Hi xxx! You’ve successfully authenticated, but GitHub does not provide shell access.

版权声明:本文为m0_51269961原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。