1

I am using git/bash in Windows 10 and try to clone a repository. When I use the command: git clone username@hostname, I get: ssh: Could not resolve hostname stbcmgit: Name or service not known

However, when I use a direct IP address instead of the hostname (git clone username@x.x.x.x), the access is successful and the clone starts.

Notes:

  • "known_hosts" file is located at c:\Users\myname\.ssh The file is taken from my Linux account where everything works fine there.
  • The .ssh folder contains also the id_rsa and id_rsa.pub keys (copied also from Linux).
  • When I use 'ls $HOME/.ssh', I see these files listed.
  • Using Windows 10.

Thanks.

Amir Meshy
  • 13
  • 4
  • Are you connecting with hostname, that resolves correctly? Ie. is configured in DNS, or `ssh_config`. Try `nslookup hostname`? – ypcs Nov 16 '17 at 13:59
  • 1
    You can follow the steps in the link: https://stackoverflow.com/questions/20252294/ssh-could-not-resolve-hostname-hostname-nodename-nor-servname-provided-or-n – Oguz Ozcan Nov 16 '17 at 14:23

3 Answers3

1

You should check /etc/hosts and add such a line if it doesn't exist:

x.x.x.x hostname

If the host's IP doesn't change, you can simplify the whole command by creating $HOME/.ssh/config like this

Host YourHost
    HostName x.x.x.x
    User username
    IdentityFile ~/.ssh/id_rsa
    PubKeyAuthentication yes

Now you can run these commands:

git clone YourHost:repo
ssh YourHost
iBug
  • 35,554
  • 7
  • 89
  • 134
0

In Windows 10 and after the latest updates concerning the "Windows Subsystem for linux" aka "Bash" now you MUST assign any desired hostname with its relative IP Address by editing this file:

C:\Windows\System32\drivers\etc\hosts

P.S: on your linux please check /etc/hosts and not the 'known_hosts' file

Viktova
  • 552
  • 7
  • 19
0

~/.ssh/config may contain such definitions.

These definitions contain port numbers also (I think /etc/hosts can't).

Zoltán
  • 1,422
  • 17
  • 22