---
title: "Mac 上的 ssh: connect to host port 22: Operation timed out · Kilobat 指南"
url: "https://kilobat.app/zh-hant/guides/ssh-port-22-operation-timed-out.html"
description: "Mac 上的 ssh 顯示 connect to host port 22: Operation timed out。先找出網路是否封鎖 SSH，再對 GitHub 改用連接埠 443，或修正 IPv6。"
---

錯誤訊息

# Mac 上的 ssh: connect to host port 22: Operation timed out

ssh 向連接埠 22 送出連線請求，卻沒有得到回應。在 Mac 上，系統的錯誤文字是「Operation timed out」；Linux 則顯示「Connection timed out」。

適用於：所有目前 macOS 版本內建的 OpenSSH。此文字已在 macOS 27.2 上以 OpenSSH 10.5 確認。 · 檢查日期：2026年10月29日

## 症狀

- 終端機顯示 `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 或代理伺服器。**流量經過一個不放行 SSH 的 VPN。
- **伺服器停機或被過濾。**伺服器在連接埠 22 上沒有回應。

## 如何檢查

1. 單獨測試 TCP 連接埠，逾時設為 5 秒。

   ```
   nc -vz -G 5 github.com 22
   ```
2. 只試 IPv4。

   ```
   ssh -4 -T git@github.com
   ```
3. 如果是 GitHub，測試連接埠 443 上的 SSH。

   ```
   ssh -T -p 443 git@ssh.github.com
   ```
4. 以詳細模式連線。最後幾行會顯示它停在哪裡。

   ```
   ssh -vT git@github.com
   ```

## 如何修正

1. 如果連接埠 443 可以用，就對 GitHub 改用它。將這個區塊加入 `~/.ssh/config`。

   ```
   Host github.com
       Hostname ssh.github.com
       Port 443
       User git
   ```
2. 如果只有 IPv4 可以用，在 `~/.ssh/config` 中該主機的區塊加入 `AddressFamily inet`。
3. 作為測試，改用儲存庫的 HTTPS URL。
4. 如果是你自己的伺服器，請網路管理者放行它的 SSH 連接埠。

## 使用 Kilobat

1. Kilobat 的連線診斷會逐層測試主機：網路、代理伺服器、DNS、規則、IPv4、IPv6、TLS 和伺服器，並指出失敗的是哪一層。

   ```
   kilobat why github.com
   ```
2. 這些 Kilobat 檢查都是免費的。AI 代理程式可透過 MCP 以 `diagnose_connection` 和 `diagnose_network` 執行。請參閱[找出某個網站或 API 連不上的原因](https://kilobat.app/zh-hant/guides/recipes/why-cant-it-connect.html)。

## 常見問題

**為什麼我的 Mac 顯示 Operation timed out，而不是 Connection timed out？**

ssh 會印出系統對這個錯誤的文字。在 macOS 上，ETIMEDOUT 的文字是「Operation timed out」。

## 資料來源

- [GitHub Docs：Using SSH over the HTTPS port](https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port)
- 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>` 開啟。

## 相關指南

- [Mac 上的 SSH 和 Git 逾時](https://kilobat.app/zh-hant/guides/ssh-git-timeouts.html): SSH 和 Git 需要與伺服器之間有正常的 TCP 連線。
- [Mac 上的 Git：「Could not resolve host: github.com」](https://kilobat.app/zh-hant/guides/git-could-not-resolve-host-github.html): Git 無法取得 github.com 的位址。
- [Mac 上的 IPv6 問題](https://kilobat.app/zh-hant/guides/ipv6-problems-mac.html): 大多數網路都會同時提供 IPv4 和 IPv6 位址給 Mac。
- [公司代理伺服器憑證導致 Mac 上的終端機工具失效](https://kilobat.app/zh-hant/guides/corporate-proxy-certificates.html): 有些公司網路會檢查 HTTPS 流量。
