Reputation: 1681
The process of setting up a GitHub account works just fine but it doesn't work when I try pushing my repository to GitHub. The error message it shows is as follows:
ssh: Could not resolve hostname github.com: Name or service not known
fatal: The remote end hung up unexpectedly
I have tried changing RSA keys and all but still getting error.
What causes this error?
Upvotes: 163
Views: 411579
Reputation: 17444
The error is actually pretty clear:
Could not resolve hostname github.com: Name or service not known
The point is, for a connection you need an IP address, so you first have to convert github.com
to one. For that, programs use your OS' DNS resolver. If that resolver has an issue (which is often just temporary due to some network changes), you can't resolve names to IP addresses and this happens.
For verification, use host github.com
which should also give you an error that it can't resolve the name. If that is not the case, retry using Git, the error could have been temporary or it could be something completely different.
Otherwise, try these steps:
ping -O 8.8.8.8
.host github.com 8.8.8.8
, which should be able to resolve the name.ping -O <address>
.FYI, 8.8.8.8 is a public DNS server operated by Google with an easy to remember IP address. You could use any other, but you must know the IP address and not just the name.
The first step is to check that you generally can reach the internet. The second tries to resolve the name via the DNS server. The third one checks general connectivity to github.com. If all work, it's a strong indication the problem is not with github.com or the internet itself. Instead, it's something caused by your OS' DNS resolver or local network.
In many cases, disabling and re-enabling your network configuration will fix this. Alternatively, switch to a different network. In desperate cases, rebooting your machine to restart the network configuration service from scratch may be necessary, but that would indicate it's a bug in that service.
Upvotes: 1
Reputation: 1497
Recently, I have seen this problem too. Below, you have my solution:
ping github.com, if ping failed, it is a DNS error.
sudo vim /etc/resolv.conf, then add:
nameserver 8.8.8.8
nameserver 8.8.4.4
Or it can be a genuine network issue. Restart your network-manager using sudo service network-manager restart
or fix it up.
Upvotes: 148
Reputation: 19
restarting my terminal did not work, so i restarted my laptop ,and it works.
Upvotes: -1
Reputation: 372
Each of this could help
ssh -T [email protected]
If you get the message that you were successfully authenticated and that GitHub doesn't support shell access, then you can try pushing your code again.
ssh -T [email protected]
Upvotes: 12
Reputation: 454
For me this resolved the issue:
sudo systemctl restart networking
Upvotes: 0
Reputation: 2002
Can you try this approach,
echo -e "[network]\ngenerateResolvConf = false\n" | sudo tee /etc/wsl.conf
echo -e "nameserver 8.8.8.8\n" | sudo tee /etc/resolv.conf
Upvotes: 5
Reputation: 617
Steps to troubleshoot here
This happen with me on SourceTree In my case, something wrong with my pair public-private key. So I delete this pair(usually store on /Users/username/.ssh) and generate new one(also add SSH on github Settings-> SSH and GPG keys manually if needed)
Upvotes: 0
Reputation: 513
I was using "WSL: Ubuntu" via VS code, closing my connection and then restarting worked for me.
Upvotes: 1
Reputation: 1
I've the same issue of recent to solve this problem all you just need to do is to connect to stable internet once you're connected to stable internet try again
Upvotes: -1
Reputation: 57332
I had the same output and turned out I had contradicting insteadof
declarations in the .gitconfig
(because I was working simultaneously on node and golang projects). You can manually delete the sections from the .gitconfig
. Though I've created a script that cleans the url sections to be able to add the insteadof declarations on a cleaner config:
for windows (should be saved as .bat
):
@echo off
setlocal
for /f "usebackq tokens=* delims=" %%# in (`git config --get user.name`) do (
set git_user=%%#
)
echo %git_user%
for /f "usebackq tokens=1,2 delims=] " %%a in (`findstr "[url " "%userprofile%\.gitconfig" ^|find /V "%git_user%:" 2^>nul`) do (
git config --global --remove-section url.%%b
)
endlocal
rem -- git config --global url.ssh://[email protected]/.insteadOf https://github.com/
bash:
#!/bin/bash
git_user=$(git config --get user.name)
git config --global -l | grep -v $git_user | grep url.| awk -F '.insteadof' '{print $1}' | while read -r url ; do
echo $url
git config --global --remove-section $url
done
And it will be a good idea .gitconfig
to be backed up.
Upvotes: 0
Reputation: 9826
Github is currently (on 22nd of feb 2012, again on 5th of sept 2016) having some problems with pushing/pulling over ssh. I'm experiencing the same problems.
Pulling over https is working thought.
You can try pushing over https by following this guide: https://help.github.com/articles/using-ssh-over-the-https-port/
This would only help if https is not affected. you can try and look at https://www.githubstatus.com/ to see if there are any reported issues at github's end.
If github is currently being DDOS'ed they may choose to enable DDOS protection from a 3rd party. This would mean they change their dns records and/or servers if these are part of the DDOS.
Flushing your dns, changing your dns server or restarting your network (which will possibly flush your dns cache) as stated in the other answer might help in fixing the issue for you if github is mitigating a DDOS.
Or if you have problems with your ssh setup you can find the ssh faq here: http://help.github.com/ssh-issues/
Other ways to flush your dns, in windows in your terminal
ipconfig /flushdns
on macos
dscacheutil -flushcache
on linux
service nscd restart
or simply rebooting ;)
Upvotes: 23
Reputation: 561
I was having the same issue, tried all the methods nothing worked.
then realized my VPN was on.
if you too have a VPN turned on try switching off your VPN and retry.
I was using Cloudflare VPN.
Upvotes: 0
Reputation: 5132
I was having this exact issue and all that I had to do was to restart my desktop
Upvotes: 7
Reputation: 388
If ping github.com gives below error: ping: cannot resolve github.com: Unknown host
Kindly wait for couple of minutes and then try again.
Upvotes: -5
Reputation: 3965
You can check which the key is being used by trying to connect to [email protected]:
$ ssh -vT [email protected]
> ...
> debug1: identity file /Users/you/.ssh/id_rsa type -1
> debug1: identity file /Users/you/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/you/.ssh/id_dsa type -1
> debug1: identity file /Users/you/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/you/.ssh/id_rsa
> debug1: Trying private key: /Users/you/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).
In that example, we did not have any keys for SSH to use. The "-1" at the end of the "identity file" lines means SSH couldn't find a file to use. Later on, the "Trying private key" lines also indicate that no file was found. If a file existed, those lines would be "1" and "Offering public key", respectively:
$ ssh -vT [email protected]
> ...
> debug1: identity file /Users/you/.ssh/id_rsa type 1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Offering RSA public key: /Users/you/.ssh/id_rsa
You must provide your public key to GitHub to establish a secure connection.
Open Terminal.
Start SSH agent in the background.
$ eval "$(ssh-agent -s)"
Agent pid 59566
Find and take a note of your public key fingerprint.
$ ssh-add -l -E sha256
2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)
In the upper-right corner of any github page, click your profile photo, then click Settings.
In the user settings sidebar, click SSH and GPG keys.
Compare the list of SSH keys with the output from the ssh-add command.
If you don't see your public key in GitHub, you'll need to add your SSH key to GitHub to associate it with your computer.
Follow this link for details
Upvotes: 1
Reputation: 171
If you use Windows 10 and you are facing this error, try using ssh -T [email protected]
to authenticate again to Github. It worked like charm for me.
Upvotes: 2
Reputation: 31
On centos 7
check ip address using command ifconfig
. you will get information like this
ens33: flags=****<UP,BROADCAST,RUNNING,MULTICAST> mtu ****
inet ***.***.***.*** netmask ***.***.***.0 broadcast ***.***.***.***
add inet ip address and hostname in file /etc/hosts
a. open file vi /etc/hosts
b. add ip and host like ip_address hostname hostname
reboot
It will attach ip and host.
Upvotes: 0
Reputation: 11
Sometimes restarting your machine is also a good idea. When I faced the same issue after restarting the system, it told me that your private key is locked and github cant access that.. so enter your password to do that.. I entered the password and then the issue was resolved.
Upvotes: 1
Reputation: 3482
In my case I had misspelled something when manually adding the remote origin with git remote add origin ...
.
It's worth checking your remote is correct with git remote -v
Upvotes: 4
Reputation: 3113
I have just received this error after switching from HTTPS to SSH (for my origin remote). To fix, I simply ran the following command (for each repo):
ssh -T [email protected]
Upon receiving a successful response, I could fetch/push to the repo with ssh.
I took that command from Git's Testing your SSH connection guide, which is part of the greater Connecting to GitHub with with SSH guide.
Upvotes: 81