天空闲话 发表于 2025-3-24 17:38:31

办理 GitHub 22 端口被占用,改用 443 端口毗连

在使用 git push 或其他 Git 操作时,如果遇到以下错误:
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 22 端口被防火墙或网络计谋限制,导致无法毗连到 GitHub 的服务器。
为了避免这一题目,可以将毗连改为 SSH 的 443 端口。以下是详细的办理方法,包括 Windows 和 Linux/Mac 的操作步调。
Linux/Mac 下操作步调

1. 修改 SSH 配置文件

SSH 的配置文件通常位于 ~/.ssh/config,如果文件不存在,可以手动创建一个:
touch ~/.ssh/config
打开文件并添加以下内容:
Host github.com
HostName ssh.github.com# **这是最重要的部分**
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
2. 验证 SSH 配置

配置完成后,通过以下下令测试毗连是否正常:
ssh -T git@github.com

如果配置乐成,应该看到雷同以下输出:
Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
3. 配置 Git 使用新端口

为确保 Git 使用新的 443 端口,可以运行以下下令:
git config --global url."ssh://git@ssh.github.com:443".insteadOf "ssh://git@github.com"

Windows 下操作步调

1. 找到 SSH 配置文件

在 Windows 下,SSH 配置文件通常位于用户目录的 .ssh 文件夹中(比方:C:\Users\<你的用户名>\.ssh\config)。如果文件不存在,可以手动创建一个:

[*]打开资源管理器并导航到 C:\Users\<你的用户名>\.ssh。
[*]在 .ssh 文件夹下,新建一个文件,命名为 config(没有扩展名)。
2. 编辑 SSH 配置文件

用记事本或其他文本编辑器打开 config 文件,添加以下内容:
Host github.com
HostName ssh.github.com# **这是最重要的部分**
User git
Port 443
PreferredAuthentications publickey
IdentityFile C:\Users\<你的用户名>\.ssh\id_rsa
注意:


[*]IdentityFile 的路径需要根据你现实存储 SSH 密钥的位置调解,通常是 id_rsa 或 id_ed25519。
3. 验证 SSH 配置

打开下令提示符或 PowerShell,运行以下下令测试毗连:
ssh -T git@github.com

如果配置正确,你应该看到以下输出:
Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
4. 配置 Git 使用新端口

在下令提示符或 PowerShell 中运行以下下令:
git config --global url."ssh://git@ssh.github.com:443".insteadOf "ssh://git@github.com"

总结

当 22 端口被占用或限制 时,通过将 SSH 毗连切换到 443 端口,即可办理无法访问 GitHub 的题目。这种方法适用于任何操作体系,尤其是在防火墙限制较严的网络环境中。
希望这篇文章能资助到你,避免由于端口题目中断工作流!
页: [1]
查看完整版本: 办理 GitHub 22 端口被占用,改用 443 端口毗连