Git SSH over port 443

Certain networks may block traffic on port 22, which is the de facto SSH port. This causes SSH operations to fail, including Git over SSH, causing failure for Git operations like:

ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository.

Verify port 443 is open

If on Windows, check that port 443 is accessible like:

Test-NetConnection -ComputerName github.com -Port 443

The result should include

TcpTestSucceeded : True

If on Linux or macOS, check that port 443 is accessible using Netcat like:

nc -zv github.com 443

Use SSH on port 443

If port 443 works to connect to the Git server, at least temporarily configure SSH to use port 443, which is typically open for HTTPS traffic. This can be persistently done by editing the user SSH config file usually located at “~/.ssh/config”.

The “IdentityFile” like “~/.ssh/github” comes from GitHub SSH key setup or similar.

Port 443 SSH Git reference:

Host github.com
  User git
  IdentityFile ~/.ssh/github
  Hostname ssh.github.com
  Port 443

Host gist.github.com
  User git
  IdentityFile ~/.ssh/github
  Hostname ssh.github.com
  Port 443

Host gitlab.com
  User git
  IdentityFile ~/.ssh/gitlab
  Hostname altssh.gitlab.com
  Port 443

Host bitbucket.org
  User git
  IdentityFile ~/.ssh/atlassian
  Hostname altssh.bitbucket.org
  Port 443

An alternative is to specify the port directly in the Git remote URL like:

git push ssh://user@host:PORT/path/to/repo.git main

For even more extreme cases such as were HTTP Agent blocking is suspected, try environment variable GIT_HTTP_USER_AGENT to mimic a web browser user agent string, for example:

export GIT_HTTP_USER_AGENT="Mozilla/5.0"

# try git commands again

Or specify environment variable GIT_SSH_COMMAND.