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

打印 上一主题 下一主题

主题 980|帖子 980|积分 2940

在使用 git push 或其他 Git 操作时,如果遇到以下错误:
  1. ssh: connect to host github.com port 22: Connection timed out
  2. fatal: Could not read from remote repository.
  3. 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,如果文件不存在,可以手动创建一个:
  1. touch ~/.ssh/config
复制代码
打开文件并添加以下内容:
  1. Host github.com
  2. HostName ssh.github.com  # **这是最重要的部分**
  3. User git
  4. Port 443
  5. PreferredAuthentications publickey
  6. IdentityFile ~/.ssh/id_rsa
复制代码
2. 验证 SSH 配置

配置完成后,通过以下下令测试毗连是否正常:
  1. ssh -T git@github.com
复制代码
如果配置乐成,应该看到雷同以下输出:
  1. Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
复制代码
3. 配置 Git 使用新端口

为确保 Git 使用新的 443 端口,可以运行以下下令:
  1. 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 文件,添加以下内容:
  1. Host github.com
  2. HostName ssh.github.com  # **这是最重要的部分**
  3. User git
  4. Port 443
  5. PreferredAuthentications publickey
  6. IdentityFile C:\Users\<你的用户名>\.ssh\id_rsa
复制代码
注意:


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

打开下令提示符或 PowerShell,运行以下下令测试毗连:
  1. ssh -T git@github.com
复制代码
如果配置正确,你应该看到以下输出:
  1. Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
复制代码
4. 配置 Git 使用新端口

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

总结

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

举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

天空闲话

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表