警告
GitHub Enterprise Server 用户: 目前不支持通过 HTTPS 端口使用 SSH 访问 GitHub Enterprise Server。
拥有数据驻留的 GitHub Enterprise Cloud 用户: 目前不支持通过 HTTPS 端口使用 SSH 访问拥有数据驻留的 GitHub Enterprise Cloud。
要测试是否可以在 HTTPS 端口上使用 SSH,请运行以下 SSH 命令
$ ssh -T -p 443 git@ssh.github.com
# Hi USERNAME! You've successfully authenticated, but GitHub does not
# provide shell access.
如果成功,太好了!如果不行,您可能需要参考我们的故障排查指南。
注意
端口 443 使用的主机名是 ssh.github.com,而不是 github.com。
现在,要克隆仓库,您可以运行以下命令
git clone ssh://git@ssh.github.com:443/YOUR-USERNAME/YOUR-REPOSITORY.git
在 HTTPS 上启用 SSH 连接
如果您能够通过端口 443 SSH 连接到 git@ssh.github.com,可以覆盖 SSH 设置,以强制所有对 GitHub.com 的连接都通过该服务器和端口进行。
要在 SSH 配置文件中设置此项,请编辑 ~/.ssh/config,并添加以下内容
Host github.com
Hostname ssh.github.com
Port 443
User git
您可以再次连接到 GitHub.com 来测试是否生效
$ ssh -T git@github.com
# Hi USERNAME! You've successfully authenticated, but GitHub does not
# provide shell access.
更新已知主机
切换到端口 443 后首次与 GitHub 交互时,可能会收到警告,提示在 known_hosts 中未找到该主机,或以其他名称找到。
# The authenticity of host '[ssh.github.com]:443 ([140.82.112.36]:443)' can't be established.
# ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
# This host key is known by the following other names/addresses:
# ~/.ssh/known_hosts:32: github.com
# Are you sure you want to continue connecting (yes/no/[fingerprint])?
如果 SSH 指纹与 GitHub 公布的指纹之一相匹配,回答“yes”是安全的。指纹列表请参见GitHub 的 SSH 密钥指纹。