1

I have my personal GitHub account and I have GitLab account for work. I am using id_ed25519 for GitHub and it works perfectly. As I read in here and here, I should be able to create two different key and use for different accounts. Therefore, I created id_rsa for GitLab and added to my GitLab account but all the time I am having below error.

Cloning into 'product'...
ssh: Could not resolve hostname gitlab.company.com: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

My config file is located on ~/.ssh/config and as shown as below

Host github
HostName github.com 
IdentityFile ~/.ssh/id_ed25519

Host gitlab.company.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa

Also, you can see which files contain .ssh folder

> ls -1
config
id_ed25519
id_ed25519.pub
id_rsa
id_rsa.pub
known_hosts
known_hosts.old

What I am doing wrong?

Serdar
  • 146
  • 8
  • 2
    That error indicates that `gitlab.company.com` isn't reachable (probably, isn't resolving). Can you `telnet gitlab.company.com 22`, or `dig gitlab.company.com +short`? Do you need to add a `Hostname` below that `Host` with an IP address or something else? – Zac Anger Jul 09 '23 at 20:22
  • How are you cloning your gitlab repo? – Ahmed Tawfik Jul 09 '23 at 20:45
  • adding to @ZacAnger's comment : a generic way to debug ssh issues is : `ssh -v gitlab.company.com` -- but as said in that other comment: it looks like a name resolving issue – LeGEC Jul 09 '23 at 20:52
  • @ZacAnger telnet output is `telnet: could not resolve gitlab.company.com/22: Name or service not known`. dig doesn't have any output. I can access to GitLab with this link `https://10.190.16.13/`. when I run VPN – Serdar Jul 10 '23 at 15:40
  • @LeGEC but `config` file should handle that. Isn't it? Or how can I fix that issue? – Serdar Jul 10 '23 at 15:43

2 Answers2

1

As you mentioned that you are trying to access 10.190.16.13. So, you need to add that link inside /etc/hosts file.

10.190.16.13    gitlab.company.com

Then it should be good to go

User
  • 58
  • 7
-2

how are you? I noticed that you provided some links as a reference for the steps you followed to create the SSH key. From those links, it seems like you are using Windows, am I right? In the post you shared, it mentions manually creating the config file. However, have you tried generating the key using the ssh-keygen command, which is available on most operating systems? It might be worth giving it a try. Check this link from GitHub: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

  • Hi Jefferson, no I am not using Windows, I am on PopOS (based Ubuntu). As I mentioned in the question I have problem with GitLab, not with GitHub. If you have any other solution, I would like to hear. – Serdar Jul 10 '23 at 15:52