[英]git ssh fails to access host but succeed when direct IP is used (Windows 10)
我在 Windows 10 中使用 git/bash 並嘗試克隆存儲庫。 當我使用命令: git clone username@hostname
,我得到: ssh:無法解析主機名 stbcmgit:名稱或服務未知
但是,當我使用直接 IP 地址而不是主機名( git clone username@xxxx
)時,訪問成功並開始克隆。
筆記:
known_hosts
”文件位於c:\\Users\\myname\\.ssh
該文件取自我的 Linux 帳戶,在那里一切正常。id_rsa
和id_rsa.pub
密鑰(也從 Linux 復制)。ls $HOME/.ssh
”時,我看到列出了這些文件。謝謝。
在Windows 10中 ,在有關“ Linux的Windows子系統”(又稱為“ Bash”)的最新更新之后,現在您必須通過編輯此文件來為其所需的主機名分配其相對IP地址:
C:\Windows\System32\drivers\etc\hosts
PS:在您的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
~/.ssh/config
可能包含這樣的定義。
這些定義還包含端口號(我認為 /etc/hosts 不能)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.