Linux SSH 连接 GitHub(22端口被封解决方案)

张开发
2026/4/20 5:26:16 15 分钟阅读

分享文章

Linux SSH 连接 GitHub(22端口被封解决方案)
背景在某些网络环境下GitHub 的 22 端口会被封锁导致 SSH 连接失败kex_exchange_identification: Connection closed by remote host Connection closed by 198.18.0.39 port 22解决步骤1. 生成 SSH Keyssh-keygen-ted25519-Cyour_emailgithub.com# 一路回车使用默认配置2. 添加公钥到 GitHub复制公钥内容cat~/.ssh/id_ed25519.pub打开 GitHub SSH 设置页Title随意填写如my-linuxKey粘贴上一步复制的内容点击Add SSH key3. 验证 443 端口可用ssh-T-p443gitssh.github.com首次连接会提示主机验证输入yes回车。成功返回Hi lonngxiang! Youve successfully authenticated, but GitHub does not provide shell access.4. 配置 SSH 默认走 443 端口cat~/.ssh/configEOF Host github.com Hostname ssh.github.com Port 443 User git EOF5. 验证配置生效ssh-Tgitgithub.com# 返回Hi lonngxiang! Youve successfully authenticated...6. 推送代码# 将 remote 改为 SSH 协议gitremote set-url origin gitgithub.com:你的用户名/你的仓库.git# 推送gitpush origin 你的分支名原理GitHub 同时支持两个 SSH 入口入口地址端口标准github.com22备用ssh.github.com443443 端口通常不会被防火墙封锁HTTPS 端口通过~/.ssh/config配置后所有对github.com的 SSH 请求会自动走备用入口对日常使用完全透明。

更多文章