Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH Config is ignored by git client

Tags:

git

ssh

gitlab

I interact with two different git repositories, both of them are GitLab implementation.

Since I need to use different users (and e-mail) to access them, I created two ssh keys: let's say id_rsa_1 and id_rsa_2. After that I wrote a ~/.ssh/config file to specify when each id_rsa file should be used. config file is:

Host gitlab.host1.com-user1
    HostName gitlab.host1.com
    User user1
    IdentityFile ~/.ssh/id_rsa_1

Host gitlab.host2.com-user2
    HostName gitlab.host2.com
    User user2
    IdentityFile ~/.ssh/id_rsa_2

My problem is every time I use git, that config file aren't take into account. It is always looking for id_rsa file.

What is wrong in my config file? Is Host just a personal identifier or is it take into account during git searching for keys?

Which user should I provide? "git" or my real user registered in each server?

What is really wrong in my config file? Thank you very much in advance.

like image 479
Juliano ENS Avatar asked Sep 27 '22 17:09

Juliano ENS


1 Answers

The Host entry is a pattern that is matched to what host you request when looking for keys. Then, HostName is what host is actually logged into, and defaults to the value for Host. So, you could say:

Host gitlab.host1.com
    User user1
    IdentityFile ~/.ssh/id_rsa_1

You could also specify gitlab.host1.com-user1 as the host when you call git, and it should work with your current config.

For more info, you can check man ssh_config.

like image 186
Aereaux Avatar answered Oct 03 '22 07:10

Aereaux