For this project i will use github as example. I have two keys id_rsa and personal_rsa.
First of all you need to create file ~/.ssh/config. Inside the file put content as follow and edit as your need
# Default configuration (ask for password if there's no key in config file)
Host *
IdentitiesOnly yes
# personal_rsa
Host personal.com
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/personal_rsa
# id_rsa
Host github.com
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
In the repos where you want to use key personal_rsa edit the ssh remote url and replace Hostname by Host, for example:
Original Repo Url: [email protected]:my-repo.git
Url To use personal_rsa: [email protected]:my-repo.git
When you want to use id_rsa key you can just keep the original repo url, because Host and HostName are the same in config.
you can do this for any ssh service.