Scenario: same git provider, for this example GitHub (this trick is provider agnostic, has been tested with GitLab as well), and we want to have SSH configured for two different users (or more): jesugmz and myseconduser.
Configure SSH config in order to get an alias with different configuration as follow:
$ cat ~/.ssh/config
Host github.com
PubkeyAuthentication yes
IdentityFile ~/.ssh/jesugmz_privatekey
User jesugmz
Host myseconduser.github.com
HostName github.com # Actually we are telling to SSH this is the real host; host directive act as alias
PubkeyAuthentication yes
IdentityFile ~/.ssh/myseconduser_privatekey
User myseconduser
In our second account repos (no extra config needed for the first one), configure git config in order to use our SSH alias:
$ cat .git/config
# ...
[remote "origin"]
url = [email protected]:myseconduser/myrepo.git
# ...
Based on https://www.ostricher.com/2015/06/how-to-use-ssh-with-multiple-github-accounts/.