Git 报错:SSH连接超时

Parker

问题

使用 Git 向 GitHub 部署代码时,报错如下(此前正常):

1
2
3
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

原因

SSH 端口被占用,重新指定一个端口即可。

注:Windows 系统查看端口占用情况的命令为:netstat -ano | findStr 端口号

解决

  • 打开 C:\用户\主机名\.ssh 文件夹

  • 新建 config 文件(不带后缀)

  • 输入以下内容后保存:

    1
    2
    3
    4
    5
    6
    Host github.com
    User GitHub注册邮箱
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443
  • 在 Git Bash 执行:

    1
    ssh -T git@github.com

    出现询问是否连接的提示,输入 yes 回车:

    1
    2
    3
    4
    5
    $ ssh -T git@github.com
    The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
    Hi x-Parker! You've successfully authenticated, but GitHub does not provide shell access.

    成功重新建立 SSH 连接。

另解

抛弃 SSH 连接方式,使用 HTTPS 连接 Github。

参考

评论
此页目录
Git 报错:SSH连接超时