“ssh: connect to host github.com port 22: Connection refused” on Mac

The connection to port 22 was refused, so a firewall or network policy most likely blocks SSH. GitHub documents SSH over the HTTPS port as a way around it.

Fix this with your agentCopies a prompt for Claude Code, Codex or any agent that can use Terminal.

My Mac has this problem: “ssh: connect to host github.com port 22: Connection refused” on Mac. Read https://kilobat.app/guides/ssh-github-port-22-connection-refused.md and work through it with me. Install the Kilobat CLI if it’s missing: brew install seifip/kilobat/kilobat. Run the guide’s Terminal and kilobat checks yourself and tell me what you find. List the steps only I can do. Ask before you change any setting.

Applies to: git and OpenSSH on all current macOS versions.Checked: 29 October 2026

Symptoms

  • git clone, git pull or git push prints ssh: connect to host github.com port 22: Connection refused.
  • HTTPS URLs for the same repository may work.
  • It happens on hotel, school and work networks.

Likely causes

  • A firewall that blocks port 22. Some networks refuse SSH. GitHub says that some firewalls refuse SSH connections altogether.
  • A proxy or VPN. A VPN or proxy can block outbound port 22.
  • A wrong host name. A typing error in the remote URL points to a host without SSH.
  • A local security app. A security app can block SSH.

How to check

  1. Show the remote URL.

    git remote -v
  2. Test port 22.

    nc -vz github.com 22
  3. Test SSH over port 443.

    ssh -T -p 443 git@ssh.github.com
  4. Read the SSH log of the failure.

    ssh -vT git@github.com

How to fix it

  1. Add this block to ~/.ssh/config. It sends GitHub traffic through port 443.

    Host github.com
        Hostname ssh.github.com
        Port 443
        User git
  2. Test again.

    ssh -T git@github.com
  3. Or switch the remote to HTTPS.

    git remote set-url origin https://github.com/OWNER/REPO.git
  4. If port 443 fails too, turn off the VPN for a short test. Turn it on again after.

With Kilobat

  1. Kilobat's connection doctor tests the address layer by layer: network, proxy, DNS, rules, IPv4, IPv6, TLS and the server. It names the layer that failed.

    kilobat why github.com
  2. These Kilobat checks are free. AI agents run them through MCP with diagnose_connection and diagnose_network. See Find why one site or API won't connect.

Questions

What should a good test print?

GitHub says that you see “Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.”

How is this different from “Operation timed out”?

Here the connection is refused at once. A timeout means no reply. See ssh: connect to host port 22: Operation timed out on Mac.

Sources

Checked on 29 October 2026.