How to fix ssh: connect to host github.com port 22: Connection timed out in Git

GitBEGINNERMEDIUMUpdated Dec 6, 2025ยท 467 views

The 'ssh: connect to host github.com port 22: Connection timed out' error occurs when your SSH client cannot establish a connection to GitHub's SSH server. This is commonly caused by firewalls or proxies blocking port 22, and can be resolved by using SSH over port 443 or switching to HTTPS.

Quick fix

Fixes ssh: connect to host github.com port 22: Connection timed out

ssh -T -p 443 git@ssh.github.com
  1. Test if SSH over port 443 works
  2. Configure SSH to use port 443 for GitHub
  3. Alternative: Use Git URL rewriting
  4. Switch to HTTPS instead of SSH
git โ€” error
ssh -T -p 443 git@ssh.github.com
ssh: connect to host github.com port 22: Connection timed out

What this error means

The "ssh: connect to host github.com port 22: Connection timed out" error indicates that your SSH connection attempt to GitHub failed because the connection could not be established within the timeout period. Port 22 is the standard SSH port, and when it's blocked, your Git operations over SSH (clone, push, pull, fetch) cannot communicate with GitHub's servers. This error is particularly common in corporate networks, educational institutions, and public WiFi environments where network administrators often block non-essential ports including port 22. The connection "times out" rather than being immediately refused because the packets are typically silently dropped by the firewall rather than actively rejected. The good news is that GitHub provides an alternative SSH endpoint on port 443 (the standard HTTPS port), which is almost never blocked since it would break all secure web traffic. This makes the error relatively straightforward to work around once you know the solution.

Typical symptoms

  • Git push, pull, fetch, or clone commands hang for 30-60 seconds before failing with 'Connection timed out'
  • SSH operations to GitHub fail but HTTPS Git operations work fine
  • The error appears after switching networks (e.g., moving from home to office)
  • Commands that previously worked suddenly fail on a new network
  • 'ssh -T git@github.com' test command times out
  • Error may also appear as 'Operation timed out' on macOS
  • CI/CD pipelines fail when running in environments with restricted network access

Common causes

  1. Firewall blocking outbound connections on port 22 (most common cause)
  2. Corporate or institutional network proxy not allowing SSH traffic
  3. ISP blocking port 22 for residential connections
  4. VPN configuration routing traffic through a restricted gateway
  5. DNS issues preventing resolution of github.com
  6. GitHub service outage affecting SSH connectivity (rare)
  7. Local firewall software (Windows Defender, iptables) blocking outbound SSH

How to fix "ssh: connect to host github.com port 22: Connection timed out"

1Test if SSH over port 443 works

GitHub offers SSH connectivity over port 443, which bypasses most firewall restrictions. Test if this alternative works:

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, proceed to the next step to make this configuration permanent.

2Configure SSH to use port 443 for GitHub

Create or edit your SSH config file to always use port 443 when connecting to GitHub:

bash
# Create the .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, then test your connection:

bash
ssh -T git@github.com

Your Git operations should now work normally without any changes to your remote URLs.

3Alternative: Use Git URL rewriting

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

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

This tells Git to automatically convert any git@github.com: URLs to use the port 443 endpoint. To verify the configuration:

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

To undo this configuration later:

bash
git config --global --unset url."ssh://git@ssh.github.com:443/".insteadOf
4Switch to HTTPS instead of SSH

If SSH continues to be problematic, you can switch your repository to use HTTPS:

bash
# Check your current remote URL
git remote -v

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

For authentication with HTTPS, you'll need to use either:
- A Personal Access Token (PAT) instead of your password
- Git Credential Manager for caching credentials

To create a PAT: Go to GitHub Settings > Developer settings > Personal access tokens > Generate new token.

5Verify your SSH key is properly configured

Ensure your SSH key is correctly set up with GitHub:

bash
# List your SSH keys
ls -la ~/.ssh

# Check if ssh-agent is running and has your key
eval "$(ssh-agent -s)"
ssh-add -l

# If no keys are listed, add your key
ssh-add ~/.ssh/id_ed25519
# or for RSA keys:
ssh-add ~/.ssh/id_rsa

Verify your public key is added to GitHub:
1. Copy your public key: cat ~/.ssh/id_ed25519.pub
2. Go to GitHub > Settings > SSH and GPG keys
3. Ensure your key is listed there

6Check your network and DNS

Verify basic network connectivity and DNS resolution:

bash
# Test DNS resolution
nslookup github.com
# or
dig github.com

# Test if you can reach GitHub at all
ping github.com

# Test HTTPS connectivity
curl -v https://github.com

If DNS fails, try using a different DNS server:

bash
# Temporarily use Google DNS (Linux)
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

# Or Cloudflare DNS
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf
7Check local firewall settings

Your local firewall might be blocking outbound SSH connections:

On Linux (iptables/ufw):

bash
# Check UFW status
sudo ufw status

# Temporarily disable to test
sudo ufw disable
# Test SSH, then re-enable
sudo ufw enable

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

On macOS:

bash
# Check if the firewall is enabled
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate

# Temporarily disable for testing
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
8Try a different network

As a diagnostic step, try connecting from a different network:

- Switch from WiFi to mobile hotspot
- Try from home if you're at the office (or vice versa)
- Use a VPN to route around network restrictions

If the connection works on a different network, the issue is definitely with your original network's firewall or proxy configuration. You'll need to use the port 443 workaround or HTTPS method described above.

Advanced notes

### SSH Config File Syntax

The SSH config file (~/.ssh/config) supports multiple hosts with different configurations. Here's a more complete example:

bash
# GitHub using port 443
Host github.com
    Hostname ssh.github.com
    Port 443
    User git
    IdentityFile ~/.ssh/github_key

# GitLab (if also blocked)
Host gitlab.com
    Hostname altssh.gitlab.com
    Port 443
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/gitlab_key

# Keep-alive to prevent disconnection
Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

### Why Port 443 Works

Port 443 is the standard port for HTTPS traffic. Blocking it would break virtually all secure web browsing, so it's almost never restricted. GitHub runs an SSH server on this port specifically to help users behind restrictive firewalls.

The trade-off is that the hostname changes from github.com to ssh.github.com, which is why the SSH config mapping is needed.

### Debugging SSH Connections

For verbose output that helps diagnose connection issues:

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

# Maximum verbosity
ssh -vvvT -p 443 git@ssh.github.com

Look for lines like:
- debug1: Connecting to... - Shows where SSH is trying to connect
- debug1: Connection established - Confirms the TCP connection worked
- debug1: identity file... - Shows which SSH key is being used

### Corporate Proxy with SSH

If your network requires a proxy, you can use ProxyCommand in your SSH config:

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

You'll need the connect utility (part of connect-proxy package on Linux) or use nc (netcat) with the appropriate flags.

### Windows-Specific Notes

On Windows, the SSH config file is located at:
- Git Bash: ~/.ssh/config (same as Unix)
- Windows native: C:\Users\YourUsername\.ssh\config

If using PuTTY or Pageant for SSH, you'll need to configure the port 443 connection in PuTTY's settings rather than the SSH config file.

### GitHub Actions and CI/CD

In CI/CD environments, you may need to configure SSH for the runner:

yaml
- name: Configure SSH for GitHub
  run: |
    mkdir -p ~/.ssh
    echo "Host github.com" >> ~/.ssh/config
    echo "  Hostname ssh.github.com" >> ~/.ssh/config
    echo "  Port 443" >> ~/.ssh/config
    echo "  User git" >> ~/.ssh/config

Frequently asked questions

What does "ssh: connect to host github.com port 22: Connection timed out" mean?
com port 22: Connection timed out" error indicates that your SSH connection attempt to GitHub failed because the connection could not be established within the timeout period. Port 22 is the standard SSH port, and when it's blocked, your Git operations over SSH (clone, push, pull, fetch) cannot communicate with GitHub's servers. This error is particularly common in corporate networks, educational institutions, and public WiFi environments where network administrators often block non-essential ports including port 22.
How do I fix "ssh: connect to host github.com port 22: Connection timed out"?
The 'ssh: connect to host github.com port 22: Connection timed out' error occurs when your SSH client cannot establish a connection to GitHub's SSH server. This is commonly caused by firewalls or proxies blocking port 22, and can be resolved by using SSH over port 443 or switching to HTTPS.
What causes "ssh: connect to host github.com port 22: Connection timed out"?
Firewall blocking outbound connections on port 22 (most common cause) Corporate or institutional network proxy not allowing SSH traffic ISP blocking port 22 for residential connections
Is the "ssh: connect to host github.com port 22: Connection timed out" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading