Git提示:ssh: Could not resolve hostname github.com: No address associated with hostname

Posted 在奋斗的大道

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git提示:ssh: Could not resolve hostname github.com: No address associated with hostname相关的知识,希望对你有一定的参考价值。

今天本地Git Push 代码推送远程分支,提示如下错误信息:

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ git push
ssh: Could not resolve hostname github.com: No address associated with hostname
fatal: Could not read from remote repository.

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

Google 一下,大家的建议是重新配置ssh Key。

重新生成GitHub SSH Key 值,请参考如下指令

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ git config user.name
zhouzhiwengang

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ git config user.email
zhouzhiwengang@163.com

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ ssh-keygen -t rsa -C "zhouzhiwengang@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/zzg/.ssh/id_rsa):
/c/Users/zzg/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/zzg/.ssh/id_rsa
Your public key has been saved in /c/Users/zzg/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:ikXfYyRhWd/897SdPdU+Q/NKTgoZVFm4a4/4qzICidw zhouzhiwengang@163.com
The key's randomart image is:
+---[RSA 3072]----+
|        oo. .+.  |
|       ... ooo   |
|      . . o ..o  |
|     . . =  .  ..|
| . o .. S =  . o*|
|  o Eo . . +o .o@|
|    ...   oo oo**|
|      . o ...=..+|
|       . o.o+.o  |
+----[SHA256]-----+

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ eval $(ssh-agent -s)
Agent pid 909

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ ssh-add /c/Users/zzg/.ssh/id_rsa
Identity added: /c/Users/zzg/.ssh/id_rsa (zhouzhiwengang@163.com)

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ clip < /c/Users/zzg/.ssh/id_rsa.pub

执行以上指令完成本机SSH Key值生成,并将生成的Key 拷贝至Git 账户/Setting/SSH key 设置。

温馨提示:SSH Key 生成时,会提示本地已经存在是否覆盖,选择y,再Enter回车。

重新尝试git 代码推送

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ ssh -T git@github.com
ssh: Could not resolve hostname github.com: No address associated with hostname

错误含义:域名解析无法找到GitHub.

Google 一下,大家的解决办法时,将GitHub IP地址配置至hosts文件。

解决Github 域名方法问题: 

第一步:查询Github 真实IP地址,可以通过 https://www.ipaddress.com/查询。

 

 第二步:在本机:C:\\Windows\\System32\\drivers\\etc\\hosts 文件中,添加如下配置:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost
140.82.113.4 github.com

至此,我的Git代码推送恢复正常。

以上是关于Git提示:ssh: Could not resolve hostname github.com: No address associated with hostname的主要内容,如果未能解决你的问题,请参考以下文章

git 提示:fatal: Could not read from remote repository.

ssh修改默认端口号后无法连接(提示ssh: Could not resolve hostname)

ssh: Could not resolve hostname git.*****-inc.com : Temporary failure in name resolution fatal: The

Mac IDEA Git "Could not read from remote repository"问题的解决

SourceTree正确配置SSH key之后仍然提示fatal: Could not read from remote repository.

码云出现错误git@gitee.com: Permission denied (publickey). fatal: Could not read from remote repository. P