[SOLVED] ssh could not resolve hostname github.com temporary failure in name resolution

If you see the error: ssh could not resolve hostname github.com temporary failure in name resolution while cloning a repository, the most likely problem is with your DN settings.

[email protected]:~$ git clone [email protected]:codetryout/codetryout.git
Cloning into 'codetryout'...
ssh: Could not resolve hostname github.com: Temporary failure in name resolution
fatal: Could not read from remote repository.

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

While this error message is clear, it could not resolve the name, sometimes it can be confusing.

Solution for GitHub Temporary failure in name resolution – the DNS error

The git command tells us it cannot reach the DNS server. We can check whether the internet and DNS service is available. I found my default DNS entry could not provide DNS service (by simply doing a test ping google.com ).

The problem was solved by adding DNS entries and (DNS service IP addresses from Google) to the resolv.conf file:

# cat /etc/resolv.conf

Note:- if you find several lines starting with the # (comments), you may leave it there or delete it and only keep this DNS IP address. Comments have no effects.

Related articles: How to set DNS servers to Google DNS or Cloudflare DNS

Verifying git clone command again

Let us try running a git clone command again

[email protected]:~$ git clone [email protected]:codetryout/codetryout.git
Cloning into 'codetryout'...
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 27 (delta 8), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (27/27), 9.49 KiB | 3.16 MiB/s, done.
Resolving deltas: 100% (8/8), done.

This is tested on Ubuntu Linux. Save configurations will work on other Linux servers or inside docker containers.

Another possible cause of this error

Another possibility of this network error is the network blocking caused by your company firewall or the VPN. , You could try disconnecting (after you obtain permission from your company to do so!) from the VPN and rerunning the git command.