2

Well, I have seen answers in the ssh post of having multiple private key, but I haven't gain enough reputations to add any comment so I have to write a new question (sorry about that).

In the post, the answer given is the config file to direct(point to) each host/username to the private key file that it suppose to use but is there any way to have a default private key file for general use, then some others private key file for some specific use?

For example, I use my school gitlab repository so I use one specific private key for it, then I have accounts on gitlab, github .... and others ssh connections that use the same private key (but different from the school one, of course).

So, is there a way to config a default private key so should it failed to use the specific key it will use the default or I have to configure everything manually?

Pang
  • 9,564
  • 146
  • 81
  • 122
New1997
  • 23
  • 5
  • The answer to the question for the multiple private key is from this post, mine was to ask an additionnal question to it https://stackoverflow.com/questions/2419566/best-way-to-use-multiple-ssh-private-keys-on-one-client – New1997 Mar 01 '18 at 23:31
  • Yes you can have multiple keys. I use the ssh config file to achieve it. There are tutorials online on this subject. – evolutionxbox Mar 01 '18 at 23:31
  • I think default key is chosen by using the wildcard match `*` in the host property. – evolutionxbox Mar 01 '18 at 23:36
  • Yeah, I know thanks, but my question is about how to make it that there is a default private key so that when you dont specified the server or username, this « default » will be use instead of add names of every server one by one – New1997 Mar 01 '18 at 23:36

1 Answers1

1

is there any way to have a default private key file for general use, then some others private key file for some specific use?

You define in your ~/.ssh/config file an entry Host *

Host h1
   ...

Host *
   IdentityFile /my/default/ssh/key

Make sure to define it last (or you would need to add exclusion patterns).

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