- Change directory into SSH key is in
~/.ssh - Generate 2 keys:
ssh-keygen -t rsa -C "email"(second key will try to overwrite, give it another name) - Create config in
~/.ssh/configwith the following content:
Host gitlab.com-erudinsky
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
# personal
Host gitlab.com-evgenyrudinsky
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
- Add keys to your GitHub/GitLab/ADO/YourChoice platform
- If run into "Too Open" permissions issue, fix:
chmod 600 ~/.ssh/id_rsa - Clone the repo replacing base url with what is in the
Hostvalue, like this:
Original: git@github.com:erudinsky/cheat-sheets.git
New: git@gitlab.com-erudinsky:erudinsky/cheat-sheets.git
gitlab.com <=> gitlab.com-erudinsky
This should be then stored in .git/config file of the repo and next time when you do git pull or git push or any other operations with repo it should just work picking correct private key to match the public key on the git server!