2

I'm trying to add 2 ssh keys in my pc to work with 2 gitlab accounts, I created 2 pair of keys and made this "config" file:

# Compte Perso
Host gitlab.com-perso
   HostName gitlab.com
   PreferredAuthentications publickey
   IdentityFile C:\Users\<path>\.ssh\id_rsa_perso

# Compte Pro
Host gitlab.com
   HostName gitlab.com
   PreferredAuthentications publickey
   IdentityFile C:\Users\<path>\.ssh\id_rsa

When I type ssh -T git@gitlab.com and ssh -T git@gitlab.com-perso, it works I have the output Wlecome to Gitlab, <username>!, but when I try to clone like this git clone git@gitlab.com-perso:<username>/<reponame>.git

it says

Unable to open connection:
Host does not existfatal: Could not read from remote repository.

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

I know the repo can be cloned because I already cloned it in another pc with ssh but I don't understand why this doesn't work please help me. I have followed this to make my config file. (it's in french)

Kenyuki
  • 65
  • 1
  • 7
  • 1
    Double check your repo name. Make sure you copy it correctly – Mad Physicist May 06 '22 at 07:03
  • 1
    @MadPhysicist The error is `Host does not exist`: I suspect this is not about the repository name, but the SSH config `Host` entry. – VonC May 06 '22 at 07:06
  • 1
    Can you confirm `ssh -T ...` logs you in as different user? because usually it doesn't. The common solution is to add `IdentitiesOnly yes` to the host definitions. – bdecaf May 06 '22 at 07:44
  • @bdecaf ssh -T gives right accounts in both situations, but I'll try IdentitiesOnly thanks – Kenyuki May 11 '22 at 10:59

3 Answers3

1

First, you can add User git in each of your entries. That way, you can use gitlab.com-perso:<usernassh -T git@gitlab.com-persome>/<reponame>.git without the git@

Second, make sure ssh -T git@gitlab.com-perso return the right account, because if seems from your question both return the same username.

Host does not exist

Double check your host entry: gitlab.com-perso should use the right '-': you might have used a '—' (a long dash) instead of the expected double hyphen (or hyphen-minus).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

thanks to @Lukasz Korbasiewicz and @bdecaf I added IdentitiesOnly yes in config file ~/.ssh/config and GIT_SSH=C:\Program Files\Git\usr\bin\ssh.exe in environment variables and it worked.

Kenyuki
  • 65
  • 1
  • 7
0

Quick google search search for your error message reveals that this problem may be related to "Little Snitch" software - if you use it disable and try again.

Also, on Windows machines you may need to modify windows system environment variables

GIT_SSH=C:\Program Files\Git\usr\bin\ssh.exe

as you can see in this StackOverflow thread

If none of this works, there are couple of other ideas out there. It's a good idea to try at least couple of them and collect some more verbose output so we can help you better if still needed.