Loading multiple SSH keys for authentication

How to load list of keys during SSH authentication for different domains?

If You are using multiple user accounts in same domain please read this article.


With SSH Config

Just add in ~/.ssh/config file all keys that SSH will try to use for authenticate.

Host *
    UseKeychain yes
    AddKeysToAgent yes
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_demo_one
    IdentityFile ~/.ssh/id_rsa_demo_two
    IdentitiesOnly yes
    PreferredAuthentications keyboard-interactive,password

With SSH agent

Just add all keys to ssh agent with command:

  • ssh-add ~/.ssh/id_rsa_demo_one
  • ssh-add ~/.ssh/id_rsa_demo_two

You can check all added identities with ssh-add -l command and public keys with ssh-add -L command.

To delete previously added key use ssh-add -d KEY_PATH command.

If this not works, You need to remove keys manually by editing ~/.gnupg/sshcontrol file.

https://unix.stackexchange.com/a/595627/198149