本文介绍: 由于放假回家,发现之前一直使用正常的git,与github无法通讯,pull和push都无法连接。

问题

由于放假回家,发现之前一直使用正常的git,与github无法通讯,pull和push都无法连接。报错如下:
connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository.

原因

可能是所在地方禁用了22端口的访问。

解决方法

由于已经翻墙,首先排除翻墙。
网上说使用http协议访问,但是这个回很慢,排除。
最终解决方法,如下:

  1. 进入linux命令行(git bash本身就是使用linux命令)
    在这里插入图片描述

  2. 进入.ssh目录下

在这里插入图片描述
3. 使用vim命令编辑如下文件

在这里插入图片描述
文件内容如下:

Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

  1. 最后保存退出即可访问

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注