How to fix the annoying error Failed to connect to raw.githubusercontent.com port 443: Connection refused while downloading files from GitHub.
You may encounter the following error when downloading a file via a terminal or command line from GitHub using wget or some other utility.
wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
--2022-12-28 13:02:52-- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)… 49.44.79.236, 2405:200:1607:2820:41::36
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|49.44.79.236|:443… failed: Connection timed out.
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2405:200:1607:2820:41::36|:443… failed: Network is unreachable.
The main reason varies for this error; as you can see, it’s related to the SSL connection from your local network in your laptop/desktop to the GitHub server. If you are facing this error from your company’s network, it might be related to the proxy setup in the git config file.
Unfortunately, you may get this error even if you are not using any proxy and connecting to GitHub from your personal laptop.
There are many ways to fix this. Try any one of the following to solve it.
Table of Contents
Fixing Error: Failed to connect to raw.githubusercontent.com port 443
Fix 1: Updating the /etc/hosts file in Linux
If you are getting this error in Ubuntu or any other Linux distribution, then you can add the following GitHub domain IPv4 addresses to resolve this.
Open the /etc/hosts file.
sudo nano /etc/hosts
Then at the end of this file, add the IP address.
185.199.108.133 raw.githubusercontent.com
Save and close the file. And try to download it from GitHub again, and it should work. If not, try the next steps.
Fix 2: Reset the proxy config
If you have a local git setup with ~/.gitconfig in your home directory, you may run the following command to reset the proxy settings.
git --global --unset http.proxy
git --global --unset https.proxy
Then restart your system. And try to see whether the error goes away.
Fix 3: Force reset the proxy to an empty string
You can also try the following command to set the proxy to an empty string. And then verify.
git config --global http.proxy ""
Fix 4: Update the proxy settings with your network details
If you are getting this error from your corporate network with private repo, you might need to ask your network admin for the username and password with GitHub proxy details. Once you have that, run the following from the terminal. Replace the username, password, address and port in the below command. Also, if your user name contains ‘@’ character, encode it to ‘%40’.
git config --global http.proxy http[s]://userName:password@proxyaddress:port
Wrapping Up
I hope you can resolve this error using any of the above methods. Please let me know in the comment box which of the above methods works.