Sunforger

Sunforger

Configuration of the config file for direct SSH connection to GitHub

When connecting to GitHub using the SSH protocol, it is usually necessary to configure the SSH config file.

Generally, the configuration file has the following fields:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_rsa

Host is the identifier for the host configuration.
HostName: the address or domain name of the host.
User: the username used to log into the host.
IdentityFile: the path to the private key file used for authentication.

When there are issues with resolving the github.com domain, you can look up the corresponding address for ssh.github.com at https://www.ipaddress.com/ (assumed to be 140.82.xxx.xx) and replace the content of the HostName field.

Then, test the connection in the command line interface using ssh -T ssh@github.com.

If the output is:

ssh: connect to host 140.82.xxx.xx port 22: Connection timed out

you can try forcing the use of port 443, i.e., ssh -T -p 443 git@github.com.

If the connection is successful, the output will be:

Hi [YOUR_USERNAME]! You've successfully authenticated, but GitHub does not provide shell access.

At this point, remember to make further modifications to the config.

The easiest approach is to directly replace it with:

Host github.com
  HostName 140.82.xxx.xx # modified
  User git
  IdentityFile ~/.ssh/github_rsa

Alternatively, you can create a new configuration:

# original (and temporarily unavailable)
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_rsa

# added
Host ssh.github.com
  HostName 140.82.xxx.xx
  User git
  IdentityFile ~/.ssh/github_rsa
  Port 443
  PreferredAuthentications publickey
  TCPKeepAlive yes

At this point, you can check the connection using ssh -T git@ssh.github.com. However, this may cause some issues, as it will be slightly inconvenient when using Git. This is because the Host identifier has changed (from github.com to ssh.github.com).

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.