做网站 违法推广类电商文案
news/
2025/9/23 22:48:53/
文章来源:
做网站 违法,推广类电商文案,wordpress 新建用户,淄博的大型网站建设ssh: connect to host github.com port 22: Connection refused
问题现象
本文以Windows系统为例进行说明#xff0c;在个人电脑上使用Git命令来操作GitHub上的项目#xff0c;本来都很正常#xff0c;突然某一天开始#xff0c;会提示如下错误ssh: connect to host gith…ssh: connect to host github.com port 22: Connection refused
问题现象
本文以Windows系统为例进行说明在个人电脑上使用Git命令来操作GitHub上的项目本来都很正常突然某一天开始会提示如下错误ssh: connect to host github.com port 22: Connection refused。 $ git pull 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: connect to host github.com port 22: Connection refused这个错误提示的是连接github.com的22端口被拒绝了。
原本以为http://github.com挂了但是浏览器访问http://github.com一切正常。
网上搜索这个报错发现很多人遇到这个问题大概有2个原因和对应解决方案
1、使用GitHub的443端口
22端口可能被防火墙屏蔽了可以尝试连接GitHub的443端口。 打开git bash
$ vim ~/.ssh/config
# Add section below to it
Host github.comHostname ssh.github.comPort 443$ ssh -T gitgithub.com Hi xxxxx! You’ve successfully authenticated, but GitHub does not provide shell access. 这个解决方案的思路是给~/.ssh/config文件里添加如下内容这样ssh连接GitHub的时候就会使用443端口。
Host github.com Hostname ssh.github.com Port 443 如果~/.ssh目录下没有config文件新建一个即可。
修改完~/.ssh/config文件后使用ssh -T gitgithub.com来测试和GitHub的网络通信是否正常如果提示Hi xxxxx! You’ve successfully authenticated, but GitHub does not provide shell access. 就表示一切正常了。
但是这个方案在我这里行不通修改后还是提示ssh: connect to host github.com port 443: Connection refused。
这个方案有效的前提是执行命令ssh -T -p 443 gitssh.github.com后不再提示connection refused所以要尝试这个方案的小伙伴先执行这条命令测试下。
2、使用https协议不要使用ssh协议
在你的GitHub的本地repo目录执行如下命令 $ git config --local -e 然后把里面的url配置项从git格式 url gitgithub.com:username/repo.git 修改为https格式 url https://github.com/username/repo.git 这个其实修改的是repo根目录下的./git/config文件。
但是这个方法在我这里同样不生效。
解决方案 网上的招都没用只能自力更生了。既然和GitHub建立ssh连接的时候提示connection refused那我们就详细看看建立ssh连接的过程中发生了什么可以使用ssh -v命令-v表示verbose会打出详细日志。 $ ssh -vT gitgithub.com OpenSSH_9.0p1, OpenSSL 1.1.1o 3 May 2022 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 从上面的信息马上就发现了诡异的地方连接http://github.com的地址居然是::1和127.0.0.1。前者是IPV6的localhost地址后者是IPV4的localhost地址。
到这里问题就很明确了是DNS解析出问题了导致http://github.com域名被解析成了localhost的ip地址就自然连不上GitHub了。
Windows下执行ipconfig /flushdns 清楚DNS缓存后也没用最后修改hosts文件增加一条github.com的域名映射搞定。 140.82.113.4 github.com 查找http://github.com的ip地址可以使用https://www.ipaddress.com/来查询也可以使用nslookup命令 nslookup github.com 8.8.8.8 nslookup是域名解析工具8.8.8.8是Google的DNS服务器地址。直接使用 nslookup github.com 就会使用本机已经设置好的DNS服务器进行域名解析ipconfig /all可以查看本机DNS服务器地址。
这个问题其实就是DNS解析被污染了有2种可能
DNS解析被运营商劫持了使用了科学上网工具 按照我上面写的解决方案操作即可解决。
References
https://chaxuri.com/archives/43.htmlhttps://stackoverflow.com/questions/15589682/ssh-connect-to-host-github-com-port-22-connection-timed-outhttps://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickeyhttps://gist.github.com/Tamal/1
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/914140.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!