欢迎光临
我们一直在努力

ssh connect to host github.com port 22 Connection refused

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

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

20160725131436_99170.jpg

上图中的iwwenbo_rsa.pub就是我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/iwwenbo_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/iwwenbo_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 iwwenbo! 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

赞(0)
未经允许不得转载:Ddmit » ssh connect to host github.com port 22 Connection refused

评论 抢沙发

登录

找回密码

注册