Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git ssh无法访问主机,但在使用直接IP时成功(Windows 10)_Windows_Git_Bash_Ssh - Fatal编程技术网

git ssh无法访问主机,但在使用直接IP时成功(Windows 10)

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

我正在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.pub
    密钥(也从Linux复制)
  • 当我使用“
    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
?您可以按照链接中的步骤进行操作:第二个建议在这种情况下似乎很有帮助,谢谢!。第一个建议在用于陆龟时很有用。