git ssh无法访问主机,但在使用直接IP时成功(Windows 10)
我正在Windows 10中使用git/bash并尝试克隆存储库。 使用命令时:git ssh无法访问主机,但在使用直接IP时成功(Windows 10),windows,git,bash,ssh,Windows,Git,Bash,Ssh,我正在Windows 10中使用git/bash并尝试克隆存储库。 使用命令时:git cloneusername@hostname,我得到: ssh:无法解析主机名stbcmgit:名称或服务未知 但是,当我使用直接IP地址而不是主机名(git clone)时username@x.x.x.x),访问成功,克隆启动 注: “known_hosts”文件位于c:\Users\myname\.ssh 该文件取自我的Linux帐户,那里一切正常 .ssh文件夹还包含id\u rsa和id\u rsa
git cloneusername@hostname
,我得到:
ssh:无法解析主机名stbcmgit:名称或服务未知
但是,当我使用直接IP地址而不是主机名(git clone)时username@x.x.x.x
),访问成功,克隆启动
注:
- “
”文件位于known_hosts
该文件取自我的Linux帐户,那里一切正常c:\Users\myname\.ssh
- .ssh文件夹还包含
和id\u rsa
密钥(也从Linux复制)id\u rsa.pub
- 当我使用“
”时,我看到列出了这些文件ls$HOME/.ssh
- 使用Windows10
谢谢。在Windows 10中,在最新更新了“Windows linux子系统”又名“Bash”之后,现在您必须通过编辑此文件为所需主机名分配其相对IP地址:
C:\Windows\System32\drivers\etc\hosts
注意:在您的linux上,请检查/etc/hosts而不是“known_hosts”文件您应该检查
/etc/hosts
,如果它不存在,请添加这样一行:
x.x.x.x hostname
如果主机的IP没有改变,您可以通过如下方式创建
$HOME/.ssh/config
来简化整个命令
Host YourHost
HostName x.x.x.x
User username
IdentityFile ~/.ssh/id_rsa
PubKeyAuthentication yes
现在,您可以运行以下命令:
git clone YourHost:repo
ssh YourHost
您是否使用正确解析的主机名连接?Ie.在DNS中配置,或
ssh\u config
。请尝试nslookup hostname
?您可以按照链接中的步骤进行操作:第二个建议在这种情况下似乎很有帮助,谢谢!。第一个建议在用于陆龟时很有用。