0

My config file on ssh seems to systematicaly apply the * rule i don't know why ?

 Host gitlab_perso
  HostName gitlab.com
  User git
  PreferredAuthentications publickey
  IdentitiesOnly yes
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/perso/id_rsa

Host gitlab.com
 Hostname gitlab.com
 AddKeysToAgent yes


    UseKeychain yes
     IdentityFile ~/.ssh/id_rsa

   Host *
     AddKeysToAgent yes
     UseKeychain yes
     IdentityFile ~/.ssh/id_rsa

so only my default ssh key ( ~/.ssh/id_rsa ) is always use . How the ssh config works ? thank your for your help !

frankiz
  • 9
  • 2
  • Is your file really indented like that? It's hard to read. – ChrisGPT was on strike May 25 '18 at 19:09
  • Stackoverflow is for [programming questions](https://stackoverflow.com/help/on-topic). Questions about **general computing hardware and software** are off-topic for Stack Overflow unless they directly involve tools used primarily for programming. You may be able to get help on [Super User](https://superuser.com/about). – President James K. Polk May 25 '18 at 19:39
  • Based on your indentation, do you expect the `Host *` section to only apply when connecting to `gitlab.com`? – chepner May 27 '18 at 14:48

1 Answers1

0

To use non-default key either use it explicitly:

ssh -i ~/.ssh/perso/id_rsa git@gitlab.com

or use the host alias from your ssh config:

ssh gitlab_perso

If you need to use the key in git you have to change the host in remote's URL:

git remote set-url origin git@gitlab_perso:user/repo.git
phd
  • 82,685
  • 13
  • 120
  • 165