兜兜零元 发表于 2024-6-29 09:33:03

办理ssh: connect to host github.com port 22: Connection timed out

当连接 GitHub 时无法连接到 22 端口时,可以尝试将端口更换为 443

[*]首先,尝试利用以下命令从 GitHub 克隆仓库:
$ git clone git@github.com:xxxxx/xxxx.git my-awesome-proj
如果出现以下错误信息:
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out

fatal: Could not read from remote repository.
这分析不能通过 22 端口连接到 GitHub。
2. 接下来,尝试利用以下命令测试 SSH 连接:
$ ssh -T git@github.com

如果再次出现连接超时的错误信息:
ssh: connect to host github.com port 22: Connection timed out
这意味着无法通过 22 端口进行 SSH 连接。
3. 尝试利用以下命令,将 SSH 连接的端口更改为 443:
$ ssh -T -p 443 git@ssh.github.com
如果表现以下信息:
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
这意味着通过 443 端口乐成进行了身份验证,但 GitHub 不提供 shell 访问权限。
4. 现在,我们需要在 ~/.ssh/config 文件中覆盖 SSH 设置。利用以下命令编辑该文件:
$ vim ~/.ssh/config
在文件中添加以下内容:
# Add section below to it
Host github.com
Hostname ssh.github.com
Port 443
生存并关闭文件。
5. 最后,再次尝试利用以下命令进行 SSH 连接:
$ ssh -T git@github.com

如果表现以下信息:
Hi xxxxx! You've successfully authenticated, but GitHub does not provide shell access.
这意味着乐成通过 443 端口进行了身份验证,并且现在可以正常连接到 GitHub。
6. 现在,您可以尝试再次克隆仓库:
$ git clone git@github.com:xxxxxx/xxxxx.git my-awesome-proj
如果表现以下信息:
Cloning into 'my-awesome-proj'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 15 (delta 0), reused 15 (delta 0), pack-reused 0
Receiving objects: 100% (15/15), 22.90 KiB | 4.58 MiB/s, done.
这意味着乐成克隆了 GitHub 上的仓库。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 办理ssh: connect to host github.com port 22: Connection timed out