How to fix ssh: connect to host github.com port 22: No route to host in Git
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- Verify basic network connectivity
- Test SSH over port 443
- Configure SSH to use port 443 for GitHub
- Alternative: Use Git URL rewriting
# Test if you can ping GitHub (may fail if ICMP is blocked, but worth checking)ping -c 4 github.com# Test DNS resolutionnslookup github.com# orhost github.com# Test HTTPS connectivity (should work if only port 22 is blocked)curl -I https://github.comssh: 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
- 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
- Local firewall (iptables, ufw, Windows Firewall) blocking outbound SSH
- VPN or proxy routing traffic through a network that blocks port 22
- Incorrect network configuration or routing table issues
- Network interface not properly connected or configured
- 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"
First, confirm that your network connection is working and that you can reach GitHub:
# 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.comIf 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.
GitHub provides an alternative SSH server on port 443, which is almost never blocked since it would break HTTPS:
ssh -T -p 443 git@ssh.github.comIf successful, you'll see:
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).
Edit your SSH config file to always use port 443 when connecting to GitHub:
# Create .ssh directory if it doesn't exist
mkdir -p ~/.ssh
# Edit (or create) the SSH config file
nano ~/.ssh/configAdd the following configuration:
Host github.com
Hostname ssh.github.com
Port 443
User gitSave the file and set appropriate permissions:
chmod 600 ~/.ssh/configTest the connection:
ssh -T git@github.comYour Git operations should now work without modifying any repository URLs.
Instead of modifying SSH config, you can configure Git to rewrite GitHub URLs:
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:
git config --global --get-regexp urlTo remove this configuration later:
git config --global --unset url."ssh://git@ssh.github.com:443/".insteadOfYour local firewall might be blocking outbound SSH:
On Linux (ufw):
# Check UFW status
sudo ufw status verbose
# Temporarily disable to test
sudo ufw disable
# After testing, re-enable
sudo ufw enableOn Linux (iptables/firewalld):
# Check if port 22 outbound is allowed
sudo iptables -L OUTPUT -n -v | grep 22
# For firewalld (RHEL/CentOS/Fedora)
sudo firewall-cmd --list-allOn 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:
# Check firewall status
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
# List blocked applications
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --listappsUse traceroute to identify where the packets are being dropped:
# 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 DetailedThe 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
If SSH continues to be problematic, switch your repositories to use HTTPS:
# Check current remote URL
git remote -v
# Change from SSH to HTTPS
git remote set-url origin https://github.com/username/repository.gitFor 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:
# Cache credentials for 1 hour
git config --global credential.helper 'cache --timeout=3600'
# Or use the system credential manager
git config --global credential.helper storeAs 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:
# Single verbose flag
ssh -vT git@github.com
# Maximum verbosity (shows all negotiation details)
ssh -vvvT -p 443 git@ssh.github.comKey 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:
# 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:
Host github.com
Hostname ssh.github.com
Port 443
User git
ProxyCommand connect -H proxy.company.com:8080 %h %pThe connect utility is from the connect-proxy package on Linux. On macOS, you can use:
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:
# Linux
ip route show
# or
netstat -rn
# macOS
netstat -rn
# Windows
route printIf 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
- 📚Git Official Documentation
- 💬Git ssh error: port 22: no route to host - Ask Ubuntu(Stack Overflow)
- 💬
- 💬Solution for GitHub SSH Connection Issues - GitHub Gist(Stack Overflow)
- 📝
- 📝
- 📖Using SSH over the HTTPS port - GitHub Docs(Official Docs)