---
title: "“ssh: connect to host github.com port 22: Connection refused” on Mac · Kilobat Guides"
url: "https://kilobat.app/guides/ssh-github-port-22-connection-refused"
description: "git or ssh on your Mac stops with connect to host github.com port 22: Connection refused. A network blocks port 22. Use SSH over port 443."
---

# “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 agent**Copies 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](https://kilobat.app/guides/recipes/why-cant-it-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](https://kilobat.app/guides/ssh-port-22-operation-timed-out).

## Sources

- [GitHub Docs: Using SSH over the HTTPS port](https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port)

Checked on 29 October 2026.

## Related guides

- [ssh: connect to host port 22: Operation timed out on Mac](https://kilobat.app/guides/ssh-port-22-operation-timed-out): ssh sent a connection request to port 22 and got no answer.
- [SSH and Git time out on a Mac](https://kilobat.app/guides/ssh-git-timeouts): SSH and Git need a working TCP connection to the server.
- [Git: “Could not resolve host: github.com” on Mac](https://kilobat.app/guides/git-could-not-resolve-host-github): Git could not get an address for github.com.
- [ERR_CONNECTION_REFUSED in Chrome on Mac](https://kilobat.app/guides/err-connection-refused): ERR_CONNECTION_REFUSED is a Chrome network error.
