git ssh:无法解析主机名 github.com:名称或服务未知;致命:远端意外挂断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9393409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:01:48  来源:igfitidea点击:

ssh: Could not resolve hostname github.com: Name or service not known; fatal: The remote end hung up unexpectedly

git

提问by Neel Pathak

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:

设置 GitHub 帐户的过程工作正常,但是当我尝试将我的存储库推送到 GitHub 时它不起作用。它显示的错误消息如下:

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.

我曾尝试更改 RSA 密钥,但仍然出现错误。

What causes this error?

是什么导致了这个错误?

回答by Qiangks

Recently, I have seen this problem too. Below, you have my solution:

最近,我也看到了这个问题。下面,你有我的解决方案:

  1. ping github.com, if ping failed. it is DNS error.
  2. sudo vim /etc/resolv.conf, the add: nameserver 8.8.8.8 nameserver 8.8.4.4
  1. ping github.com,如果 ping 失败。这是DNS错误。
  2. sudo vim /etc/resolv.conf,添加: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 restartor fix it up

或者它可能是一个真正的网络问题。使用sudo service network-manager restart或修复它重新启动您的网络管理器

回答by Jens Timmerman

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.

Github 目前(2012 年 2 月 22 日,2016 年 9 月 5 日)在推/拉 ssh 时遇到一些问题。我遇到了同样的问题。

Pulling over https is working thought.

拉过 https 是可行的想法。

You can try pushing over https by following this guide: https://help.github.com/articles/using-ssh-over-the-https-port/

您可以按照本指南尝试推送 https:https: //help.github.com/articles/using-ssh-over-the-https-port/

This would only help if https is not affected. you can try if https://status.github.com/shows signs of things slowing down. enter image description hereGraphs where the mean response time goes up means there are issues (or possibly a DDOS) at github, and not at your end.

这只会在 https 不受影响的情况下有所帮助。如果https://status.github.com/显示速度变慢的迹象,您可以尝试。 enter image description here平均响应时间上升的图表意味着在 github 上存在问题(或可能是 DDOS),而不是在你的最后。

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.

如果 github 当前正在被 DDOS 攻击,他们可能会选择启用来自第 3 方的 DDOS 保护。如果这些是 DDOS 的一部分,这意味着他们会更改他们的 dns 记录和/或服务器。

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.

如果 github 正在缓解 DDOS,则如另一个答案中所述,刷新您的 dns、更改您的 dns 服务器或重新启动您的网络(这可能会刷新您的 dns 缓存)可能有助于为您解决问题。

Or if you have problems with your ssh setup you can find the ssh faq here: http://help.github.com/ssh-issues/

或者,如果您的 ssh 设置有问题,您可以在此处找到 ssh 常见问题解答:http: //help.github.com/ssh-issues/

Other ways to flush your dns, in windows in your terminal

在终端窗口中刷新 dns 的其他方法

ipconfig /flushdns

on macos

在 macos 上

dscacheutil -flushcache

on linux

在 linux 上

service nscd restart

or simply rebooting ;)

或者干脆重新启动 ;)

回答by Todd

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):

从 HTTPS 切换到 SSH(对于我的远程源)后,我刚刚收到此错误。要修复,我只需运行以下命令(对于每个 repo):

ssh -T [email protected]

ssh -T [email protected]

Upon receiving a successful response, I could fetch/push to the repo with ssh.

收到成功响应后,我可以使用 ssh 获取/推送到存储库。

I took that command from Git's Testing your SSH connectionguide, which is part of the greater Connecting to GitHub with with SSHguide.

我从 Git 的测试您的 SSH 连接指南中获取了该命令,该指南是使用 SSH指南连接到 GitHub 的一部分。

回答by Skylar Brown

In my case I had misspelled something when manually adding the remote origin with git remote add origin ....

在我的情况下,我在手动添加远程源时拼错了一些东西git remote add origin ...

It's worth checking your remote is correct with git remote -v

值得检查您的遥控器是否正确 git remote -v

回答by Namrata

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.

有时重新启动机器也是一个好主意。当我在重新启动系统后遇到同样的问题时,它告诉我你的私钥被锁定并且 github 无法访问......所以输入你的密码来做到这一点......我输入了密码,然后问题解决了。

回答by Birbal Sain

On centos 7

在centos 7

  1. check ip address using command ifconfig. you will get information like this

    ens33: flags=****<UP,BROADCAST,RUNNING,MULTICAST>  mtu ****
    
    inet ***.***.***.***  netmask ***.***.***.0  broadcast ***.***.***.***
    
  2. 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

  3. reboot

  1. 使用命令检查ip地址ifconfig。你会得到这样的信息

    ens33: flags=****<UP,BROADCAST,RUNNING,MULTICAST>  mtu ****
    
    inet ***.***.***.***  netmask ***.***.***.0  broadcast ***.***.***.***
    
  2. 在文件中添加 inet ip 地址和主机名 /etc/hosts

    一种。打开文件vi /etc/hosts

    湾 添加ip和主机就像ip_address hostname hostname

  3. 重启

It will attach ip and host.

它将附加ip和主机。