How to fix ssh: connect to host github.com port 22: No route to host in Git

GitBEGINNERMEDIUMUpdated Dec 6, 2025· 325 views

The 'ssh: connect to host github.com port 22: No route to host' error means your system cannot find a network path to reach GitHub's SSH server. This typically indicates a network-level issue such as firewall blocking, incorrect routing, or the SSH port being filtered by your ISP or network administrator.

Quick fix

Fixes ssh: connect to host github.com port 22: No route to host

# Test if you can ping GitHub (may fail if ICMP is blocked, but worth checking)
ping -c 4 github.com

# Test DNS resolution
nslookup github.com
# or
host github.com

# Test HTTPS connectivity (should work if only port 22 is blocked)
curl -I https://github.com
  1. Verify basic network connectivity
  2. Test SSH over port 443
  3. Configure SSH to use port 443 for GitHub
  4. Alternative: Use Git URL rewriting
git — error
# Test if you can ping GitHub (may fail if ICMP is blocked, but worth checking)
ping -c 4 github.com
# Test DNS resolution
nslookup github.com
# or
host github.com
# Test HTTPS connectivity (should work if only port 22 is blocked)
curl -I https://github.com
ssh: connect to host github.com port 22: No route to host

What this error means

The "ssh: connect to host github.com port 22: No route to host" error is a network-layer failure that occurs when your operating system cannot establish a route to reach GitHub's SSH server on port 22. Unlike a "Connection refused" error (where the host is reached but rejects the connection) or "Connection timed out" (where packets are sent but no response is received), "No route to host" indicates that your system's network stack has determined there is no valid path to the destination. This error typically originates from one of three places: your local firewall actively blocking the connection, a router or gateway along the path rejecting the traffic, or ICMP "destination unreachable" messages being sent back from network infrastructure. The error is common in corporate networks, educational institutions, and environments where network administrators deliberately block SSH traffic on port 22. The good news is that GitHub provides an alternative SSH endpoint on port 443 (ssh.github.com), which is rarely blocked since blocking it would disrupt all HTTPS web traffic. This makes the error relatively straightforward to work around once you identify it as a port blocking issue.

Typical symptoms

  • Git push, pull, clone, or fetch commands fail immediately with 'No route to host'
  • SSH operations to GitHub fail but HTTPS Git operations work normally
  • The error appears after switching networks (e.g., connecting to corporate WiFi)
  • 'ssh -T git@github.com' test command fails with 'No route to host'
  • Commands work on some networks but not others
  • The error occurs immediately rather than after a timeout delay
  • Other SSH connections to port 22 on different hosts may also fail
  • CI/CD pipelines fail when running in restricted network environments

Common causes

  1. Network firewall blocking outbound connections on port 22 (most common)
  2. Router or gateway configured to drop SSH traffic
  3. ISP filtering port 22 for residential or business connections
  4. Local firewall (iptables, ufw, Windows Firewall) blocking outbound SSH
  5. VPN or proxy routing traffic through a network that blocks port 22
  6. Incorrect network configuration or routing table issues
  7. Network interface not properly connected or configured
  8. DNS resolution succeeds but routing to the resolved IP fails

How to fix "ssh: connect to host github.com port 22: No route to host"

1Verify basic network connectivity

First, confirm that your network connection is working and that you can reach GitHub:

bash
# Test if you can ping GitHub (may fail if ICMP is blocked, but worth checking)
ping -c 4 github.com

# Test DNS resolution
nslookup github.com
# or
host github.com

# Test HTTPS connectivity (should work if only port 22 is blocked)
curl -I https://github.com

If DNS resolution fails, you have a DNS problem, not a routing problem. If ping fails but curl works, ICMP may be blocked which is normal on many networks. If curl to HTTPS works, proceed to test SSH on port 443.

2Test SSH over port 443

GitHub provides an alternative SSH server on port 443, which is almost never blocked since it would break HTTPS:

bash
ssh -T -p 443 git@ssh.github.com

If successful, you'll see:

bash
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

If this works, port 22 is being blocked and you should configure SSH to use port 443 permanently (next step).

3Configure SSH to use port 443 for GitHub

Edit your SSH config file to always use port 443 when connecting to GitHub:

bash
# Create .ssh directory if it doesn't exist
mkdir -p ~/.ssh

# Edit (or create) the SSH config file
nano ~/.ssh/config

Add the following configuration:

bash
Host github.com
    Hostname ssh.github.com
    Port 443
    User git

Save the file and set appropriate permissions:

bash
chmod 600 ~/.ssh/config

Test the connection:

bash
ssh -T git@github.com

Your Git operations should now work without modifying any repository URLs.

4Alternative: Use Git URL rewriting

Instead of modifying SSH config, you can configure Git to rewrite GitHub URLs:

bash
git config --global url."ssh://git@ssh.github.com:443/".insteadOf "git@github.com:"

This automatically converts any git@github.com: URLs to use the port 443 endpoint. Verify the configuration:

bash
git config --global --get-regexp url

To remove this configuration later:

bash
git config --global --unset url."ssh://git@ssh.github.com:443/".insteadOf
5Check local firewall settings

Your local firewall might be blocking outbound SSH:

On Linux (ufw):

bash
# Check UFW status
sudo ufw status verbose

# Temporarily disable to test
sudo ufw disable

# After testing, re-enable
sudo ufw enable

On Linux (iptables/firewalld):

bash
# Check if port 22 outbound is allowed
sudo iptables -L OUTPUT -n -v | grep 22

# For firewalld (RHEL/CentOS/Fedora)
sudo firewall-cmd --list-all

On Windows:
1. Open Windows Defender Firewall
2. Click "Allow an app through firewall"
3. Ensure Git, OpenSSH, or your SSH client is allowed for outbound connections

On macOS:

bash
# Check firewall status
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate

# List blocked applications
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --listapps
6Use traceroute to diagnose the route

Use traceroute to identify where the packets are being dropped:

bash
# On Linux
traceroute -T -p 22 github.com

# On macOS
traceroute -P tcp -p 22 github.com

# On Windows (PowerShell)
Test-NetConnection -ComputerName github.com -Port 22 -InformationLevel Detailed

The traceroute output shows each hop your packets take. If you see asterisks (*) or the route stops at a certain hop, that's where your traffic is being blocked. This is often at:
- Your local router (first few hops)
- Your ISP's gateway
- A corporate firewall

7Switch to HTTPS instead of SSH

If SSH continues to be problematic, switch your repositories to use HTTPS:

bash
# Check current remote URL
git remote -v

# Change from SSH to HTTPS
git remote set-url origin https://github.com/username/repository.git

For HTTPS authentication, you'll need a Personal Access Token (PAT):
1. Go to GitHub > Settings > Developer settings > Personal access tokens
2. Generate new token with appropriate scopes (repo access)
3. Use the token as your password when prompted

To cache credentials so you don't have to re-enter them:

bash
# Cache credentials for 1 hour
git config --global credential.helper 'cache --timeout=3600'

# Or use the system credential manager
git config --global credential.helper store
8Try a different network

As a diagnostic step, test from a different network:

- Use your mobile phone as a hotspot
- Connect from home if you're at the office (or vice versa)
- Use a VPN to route around network restrictions
- Try from a coffee shop or public WiFi

If SSH works on a different network, the issue is definitively with your original network's configuration. Your options are:
1. Use the port 443 workaround (recommended)
2. Use HTTPS instead of SSH
3. Request that your network administrator unblock port 22 to github.com

Advanced notes

### Understanding "No Route to Host" vs Other SSH Errors

| Error Message | Meaning |
|--------------|---------|
| No route to host | Network layer failure - no path to destination exists |
| Connection refused | Host reached, but port is not open or actively rejecting |
| Connection timed out | Packets sent but no response (often firewall silently dropping) |
| Host key verification failed | Connected successfully but SSH key mismatch |

"No route to host" is typically faster to fail than "Connection timed out" because the network stack immediately knows there's no valid route rather than waiting for a response.

### Verbose SSH Debugging

For detailed connection debugging:

bash
# Single verbose flag
ssh -vT git@github.com

# Maximum verbosity (shows all negotiation details)
ssh -vvvT -p 443 git@ssh.github.com

Key lines to look for:
- debug1: Connecting to github.com... - Where SSH is trying to connect
- debug1: connect to address X.X.X.X port 22: No route to host - Confirms the error
- debug1: Connection established - Success indicator

### Multiple Git Hosting Services

If you use multiple services (GitHub, GitLab, Bitbucket), you can configure all of them in your SSH config:

bash
# GitHub on port 443
Host github.com
    Hostname ssh.github.com
    Port 443
    User git

# GitLab on port 443 (also supports this)
Host gitlab.com
    Hostname altssh.gitlab.com
    Port 443
    User git

# Keep-alive for all connections
Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

### Corporate Proxy Configuration

If your network requires a proxy, use ProxyCommand:

bash
Host github.com
    Hostname ssh.github.com
    Port 443
    User git
    ProxyCommand connect -H proxy.company.com:8080 %h %p

The connect utility is from the connect-proxy package on Linux. On macOS, you can use:

bash
brew install connect

### Windows-Specific Configuration

On Windows, the SSH config file location depends on your setup:
- Git Bash: ~/.ssh/config (same as Unix)
- Windows OpenSSH: C:\Users\YourName\.ssh\config
- PuTTY: Configure in PuTTY's session settings, not a config file

### Checking Route Tables

To see your system's routing table:

bash
# Linux
ip route show
# or
netstat -rn

# macOS
netstat -rn

# Windows
route print

If you see an unusual default gateway or missing routes, that could explain the error. This is rare but can happen with misconfigured VPN clients.

Frequently asked questions

What does "ssh: connect to host github.com port 22: No route to host" mean?
com port 22: No route to host" error is a network-layer failure that occurs when your operating system cannot establish a route to reach GitHub's SSH server on port 22. Unlike a "Connection refused" error (where the host is reached but rejects the connection) or "Connection timed out" (where packets are sent but no response is received), "No route to host" indicates that your system's network stack has determined there is no valid path to the destination. This error typically originates from one of three places: your local firewall actively blocking the connection, a router or gateway along the path rejecting the traffic, or ICMP "destination unreachable" messages being sent back from network infrastructure.
How do I fix "ssh: connect to host github.com port 22: No route to host"?
The 'ssh: connect to host github.com port 22: No route to host' error means your system cannot find a network path to reach GitHub's SSH server. This typically indicates a network-level issue such as firewall blocking, incorrect routing, or the SSH port being filtered by your ISP or network administrator.
What causes "ssh: connect to host github.com port 22: No route to host"?
Network firewall blocking outbound connections on port 22 (most common) Router or gateway configured to drop SSH traffic ISP filtering port 22 for residential or business connections
Is the "ssh: connect to host github.com port 22: No route to host" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading