github ssh连接超时
遇到报错:
ssh: connect to host github.com port 22: connection timed out
通常意味着网络无法通过默认的 ssh 端口(22)连接到 github。
github 为 ssh 连接提供了一个备用端口(443),这通常能解决端口 22 被防火墙或网络策略阻止的问题。
这是最可能快速解决问题的方案。
操作步骤
1. 修改 ssh 配置文件
打开或创建 ssh 配置文件:
在文件中添加以下内容:
- linux/macos:
~/.ssh/config
- windows:
c:\users\<你的用户名>\.ssh\config
host github.com hostname ssh.github.com user git port 443 preferredauthentications publickey identityfile ~/.ssh/id_rsa # 如果密钥是其他名称或路径,请修改此处,例如 id_ed25519
对于 windows 用户,identityfile
路径可能需要写全,例如 identityfile c:\users\<你的用户名>\.ssh\id_rsa
2. 验证连接
保存配置文件后,打开终端(terminal/git bash),运行以下命令测试连接:
ssh -t git@github.com
如果配置成功,会看到类似的成功验证消息:
hi <your-username>! you've successfully authenticated, but github does not provide shell access.
3. 再次克隆
再次运行git clone
命令查看问题是否解决。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论