Using multiple repos with Git (which relies on OpenSSH) terminal/CLI while keeping security a priority with separate keys requires an initial config. Here is a must-know „trick“ if you need similar setup. You will need to create a file called „config
“ (yes, no file extension) in you .ssh/
folder. The sample file below provides more details.
# Alias
Host <host-name>
# Host domain or IP
HostName <host-ip/domain>
# (Optional) Username - when using SSH
User <host-username>
# Path to file identity file (i.e. private key)
IdentityFile <path-to-private-key>
In a scenario where we need access to both Gitlab and Github, an actual example would be:
# Github
Host github.com
HostName github.com
IdentityFile ~/.ssh/github_rsa
# Gitlab
Host gitlab.com
HostName gitlab.com
IdentityFile ~/.ssh/gitlab_rsa
This way when you try to execute a git pull
from either GitLab or GitHub you will be using the appropriate key for the corresponding repo.
Cheers!