Troubleshooting Git SSH Connection Issues After Changing Server Ports

If you've recently changed the SSH port on your server and are encountering connection timeout errors while trying to pull from GitHub, you're not alone. This guide walks you through diagnosing and resolving issues related to SSH configurations, network restrictions, and Git remote URLs to ensure smooth Git operations. Learn how to maintain your custom server settings while keeping seamless access to GitHub repositories.

The issue might be due to the fact that GitHub's SSH server does not support connections on ports other than the default port 22. Changing the SSH port on your server does not affect GitHub's SSH port.

To solve this, you should revert the SSH port for GitHub operations back to port 22. Here’s a possible workaround if you must use a non-standard port for other reasons:

Keep GitHub Operations on Port 22

  1. Use SSH Configuration for GitHub: Ensure that your SSH configuration is set to use port 22 for GitHub:

Separate SSH Configurations

If you need to keep separate configurations for different hosts, you can set up the SSH config file with distinct entries for each:

shCopy codenano ~/.ssh/config
shCopy code# Configuration for GitHub
Host github.com
  Hostname github.com
  User git
  Port 22

# Configuration for your own server
Host myserver
  Hostname myserver.com or ip
  User your-username
  Port 2225