使用 ssh 在 Windows 下克隆 github.com 的 repo 时出现“没有与名称关联的地址”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8159522/
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-09 08:56:35  来源:igfitidea点击:

"no address associated with name" error when cloning github.com's repo under Windows using ssh

windowsgitsshgithub

提问by Piotr Dobrogost

Searchinggoogle for +github +ssh "no address associated with name"gives the following SO questions as the 4 top results:

搜索google+github +ssh "no address associated with name"会给出以下 SO 问题作为 4 个最高结果:

github no address associated with name
Github push origin master not working
Syncing with github
GITHUB setup - no address associated with name

github 没有与名称关联的地址
Github push origin master 不工作
与 github GITHUB 设置同步
- 没有与名称关联的地址

None of them gives answer to my problem, though.

不过,他们都没有回答我的问题。

c:\Program Files (x86)\Git\bin>git --version
git version 1.7.7.1.msysgit.0

c:\Program Files (x86)\Git\bin>ssh [email protected]
Enter passphrase for key '/c/Users/Piotr/.ssh/id_rsa':
Hi piotr-dobrogost! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

c:\Program Files (x86)\Git\bin>git clone ssh://[email protected]:piotr-dobrogost/requests.git
Cloning into requests...
ssh: github.com:piotr-dobrogost: no address associated with name
fatal: The remote end hung up unexpectedly

I guess the problem is caused by git passing github.com:piotr-dobrogostas the hostname to ssh instead just github.comonly. Why does git do this and what's the solution?

我猜这个问题是由 gitgithub.com:piotr-dobrogost作为主机名传递给 ssh 而引起的github.com。为什么 git 这样做,解决方案是什么?

回答by Edward Thomson

You answered it yourself - the problem is that you're passing github.com:piotr-dobrogostas the hostname, which is, in fact, not a valid hostname. git will understand either proper URLs to a repository, or a repository path in SCP format (see man 1 scp.) For a proper URL, try:

你自己回答了 - 问题是你github.com:piotr-dobrogost作为主机名传递,实际上,这不是一个有效的主机名。git 将理解存储库的正确 URL,或 SCP 格式的存储库路径(请参阅 参考资料man 1 scp。)对于正确的 URL,请尝试:

git clone ssh://[email protected]/piotr-dobrogost/requests.git

Which is equivalent to the following in SCP path format:

这相当于 SCP 路径格式中的以下内容:

git clone [email protected]:piotr-dobrogost/requests.git

回答by Ido Ran

I had this same problem, and it's turn out it was DNS problem. The DNS settings were wrong and the machines simply could not reach the remote git repository.

我遇到了同样的问题,结果是 DNS 问题。DNS 设置错误,机器根本无法访问远程 git 存储库。

回答by johnwbyrd

I am running a private git server with an address assigned by DHCP; this address seems to remain static. From time to time, authenticating with the remote host gives the "no address associated with this name" error.

我正在运行一个由 DHCP 分配的地址的私有 git 服务器;这个地址似乎保持不变。有时,与远程主机进行身份验证时会出现“没有与此名称关联的地址”错误。

However, I edit the known_hosts file for my client (which for me resides at C:\Users\MyUserName\.ssh\known_hosts) and delete the line that refers to the private git server:

但是,我为我的客户端编辑 known_hosts 文件(对我来说它位于 C:\Users\MyUserName\.ssh\known_hosts)并删除引用私有 git 服务器的行:

gitserver.local,10.0.0.10 ssh-rsa AAAABCAAAA....

I then connect again to the git server and issue a pull request. This time, git asks whether to cache the SSH key and the pull concludes successfully, without the "no address associated with name" error.

然后我再次连接到 git 服务器并发出拉取请求。这次git询问是否缓存SSH key,pull成功结束,没有出现“no address associated with name”错误。

So, I suspect that something about the RSA key, or how that key relates to DNS, is getting screwed up. If nothing else gives joy, try manually deleting and automatically reinstalling the RSA key on the client. This should not actually work, but it seems to work in my case. I have no clear idea why this should be so.

所以,我怀疑 RSA 密钥的某些事情,或者该密钥与 DNS 的关系,正在被搞砸。如果没有其他的乐趣,请尝试在客户端上手动删除并自动重新安装 RSA 密钥。这实际上不应该起作用,但在我的情况下似乎有效。我不清楚为什么会这样。