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 [email protected]
and ssh -T [email protected]
, it works I have the output Wlecome to Gitlab, <username>!
, but when I try to clone like this git clone [email protected]:<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)
CodePudding user response:
First, you can add User git
in each of your entries. That way, you can use gitlab.com-perso:<usernassh -T [email protected]>/<reponame>.git
without the git@
Second, make sure ssh -T [email protected]
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).
CodePudding user response:
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.