ssh connect to host github.com port 22 Connection refused

洼地云 tuoyidashi.png

背景:电脑(win10)重装后,提交(push)代码提示ssh: connect to host github.com port 22: Connection refused,无法进行代码提交。

在windows上更新了git仓库中的代码后,由于我前阵子刚重装了系统,ssh key都是重新生成的,而且我本机上有一个gitlab账号,有一个github账号,都放在~/.ssh目录下,具体文件如下:

2024-01-22_060812.png

上图中的yomige_rsa就是我github账户的私钥,然后就是我提交代码时候的报错信息如下:

$ git push origin master
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/config文件,将github.com的HostName更改为下列内容,并指定端口,内容如下:

#default gitlab
    Host gitlab
      HostName gitlab
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/id_rsa    

    Host github.com
      HostName ssh.github.com
      Port 443
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/yomige_rsa

==============2016年7月26日更新================

后来发现,我这里无法进行连接的原因竟是我在hosts文件里加的github的ip无法访问了,我就把hosts文件里关于github的ip全部删掉了,然后更改~/.ssh/config文件为下列内容(我有一个gitlab账号,一个github账号):

 #default gitlab
    Host gitlab
      HostName gitlab
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/id_rsa    

    Host github.com
      HostName github.com
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/yomige_rsa

然后使用如下命令进行ssh测试,根据提示把主机添加到~/.ssh/known_hosts文件中,然后就正常了:

$ ssh -T [email protected]
The authenticity of host 'github.com (192.30.253.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
Hi yomige! You've successfully authenticated, but GitHub does not provide shell access.

内容参考:Github (SSH) via public WIFI, port 22 blocked.

参考文章:https://www.w3cmm.com/javascript/resize.html

赞(1)
未经允许禁止转载:优米格 » ssh connect to host github.com port 22 Connection refused

评论 抢沙发

合作&反馈&投稿

商务合作、问题反馈、投稿,欢迎联系

广告合作侵权联系

登录

找回密码

注册