Git SSH over port 443

Certain networks may block traffic on port 22, which causes failure for Git operations like:

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

The solution for this is to 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”, here for GitHub, where “/.ssh/github” comes from GitHub SSH key setup.

Likewise for

Host 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.