I can't fetch from GitHub using public Wi-Fi

2022-06-28 Tue 00:00

I was at a cafe near my house, tinkering with my blog site. I ran into a problem when trying to fetch from my remote git repository in GitHub. In my case, the problem was the SSH connection.

What is the problem?

I was connecting to GitHub using the SSH key I set up from the GitHub website. When I ran the command git fetch origin, it took forever to finish and eventually an error message showed up.

$ git fetch origin 
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

The only different thing from home was that I was in a cafe and using a public Wi-Fi. I looked this up and this post on StackOverflow came up. It was about not being able to connect to GitHub from port 22, which is the port used by SSH. I was hoping this was also my problem, I checked my SSH connection.

$ ssh -T git@ssh.github.com
Hi genenakagaki! You've successfully authenticated, but GitHub does not provide shell access.

This was not my expected output, so I specified the port to 22 and tried again.

$ ssh -T -p 22 git@ssh.github.com
Hi genenakagaki! You've successfully authenticated, but GitHub does not provide shell access.

It didn't seem like SSH was the problem. But not knowing what else to do, I decided to set up SSH to use the HTTPS port. It turns out that setting this up resolved this issue.

Setting up SSH to use the HTTPS port for GitHub

GitHub had a guide that showed how you can use SSH over the HTTPS port.

First, the guide tells you to check that SSH works using the HTTPS port (443).

$ ssh -T -p 443 git@ssh.github.com
Hi genenakagaki! You've successfully authenticated, but GitHub does not provide shell access.

Well, for me I was already having the same output with the SSH port (22), but it's nice to know that the HTTPS works as well.

Next, the guide tells you how to configure SSH so that when you make a connection to GitHub, you use the HTTPS port. I put the following configuration in the file ~/.ssh/config.

Host github.com
Hostname ssh.github.com
Port 443
User git

Finally, the guide tells you to check that the SSH connection works.

$ ssh -T git@github.com
Hi genenakagaki! You've successfully authenticated, but GitHub does not provide shell access.

The output doesn't really say much to me because I already had the same output… but it works!! After setting this up, I tried the git fetch origin command and it finished with no errors. Yay!! Now that I can happily use the git repository at GitHub at my cafe, I was curious if the same thing happens with GitLab.

How about GitLab

I tried the same command git fetch origin on a git repository on GitLab. Strangely there were no issues with the command and it finished without any errors. I looked up if a similar configuration can be done with GitLab also. I found a guide so I went ahead and set it up, thinking that other public Wi-Fi might be restricting the SSH port.

Setting up SSH to use the HTTPS port for GitLab

I found a blog post that shows you how to set up the SSH to use the HTTPS port. I also found it in the docs. Similar to the GitHub configuration, I needed to add stuff to the ~/.ssh/config file.

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

After setting this up, the git fetch origin command still finishes without errors so I think it's working. I can finally start tinkering with my blog site!