错误信息
Mac 上出现 ssh: connect to host port 22: Operation timed out
ssh 向端口 22 发出了连接请求,但没有收到应答。在 Mac 上,系统给出的错误文字是“Operation timed out”;Linux 上则是“Connection timed out”。
症状
- “终端”显示
ssh: connect to host github.com port 22: Operation timed out。 - 随后 Git 显示
fatal: Could not read from remote repository. - 在其他网络(例如家里的网络)上,SSH 能正常使用。
可能的原因
- 网络屏蔽了端口 22。公司、学校、酒店和公共网络常常屏蔽 SSH。GitHub 表示,防火墙有时会拒绝 SSH 连接。
- IPv6 路径不通。Mac 会先尝试 IPv6,而 IPv6 无法使用。
- VPN 或代理。流量经过的 VPN 不放行 SSH。
- 服务器宕机或被过滤。服务器没有在端口 22 上应答。
如何检查
单独测试 TCP 端口,超时时间设为 5 秒。
nc -vz -G 5 github.com 22只用 IPv4 试试。
ssh -4 -T git@github.com对于 GitHub,测试端口 443 上的 SSH。
ssh -T -p 443 git@ssh.github.com以详细模式连接。最后几行会显示连接停在哪一步。
ssh -vT git@github.com
如何修复
如果端口 443 可用,就为 GitHub 使用它。将以下配置块添加到
~/.ssh/config。Host github.com Hostname ssh.github.com Port 443 User git如果只有 IPv4 可用,在
~/.ssh/config中该主机的配置块里添加AddressFamily inet。作为测试,改用仓库的 HTTPS URL。
如果是你自己的服务器,请网络管理员放行它的 SSH 端口。
使用 Kilobat
Kilobat 的连接诊断逐层测试主机:网络、代理、DNS、规则、IPv4、IPv6、TLS 和服务器,并指出失败的那一层。
kilobat why github.comKilobat 的这些检查都是免费的。AI 智能体可以通过 MCP 用
diagnose_connection和diagnose_network运行它们。请参阅找出某个网站或 API 连不上的原因。
常见问题
为什么 Mac 显示 Operation timed out,而不是 Connection timed out?
ssh 打印的是系统对该错误的描述文字。在 macOS 上,ETIMEDOUT 对应的文字是“Operation timed out”。
参考资料
- GitHub 文档:在 HTTPS 端口使用 SSH
- ssh(1)、ssh_config(5) 和 nc(1),macOS 27.2 自带的 man 手册页
- intro(2),ETIMEDOUT,macOS 27.2 自带的 man 手册页
参考资料核查于 2026年10月29日。man 手册页为 macOS 自带版本;在“终端”中用 man <name> 打开。