Git SSH Keys and Config
Deven Mistry -- Aug 8 2022
GQC was initially using Bitbucket for hosting its repositories and version control. GQC is now slowly migrating to GitHub.
GitHub
To setup a SSH key in GitHub, please follow the instructions mentioned over here.
Bitbucket
To setup SSH for Bitbucket, please follow the instructions mentioned over here.
⚠️ The command eval $(ssh-agent) needs to be executed in a bash window.
Dealing with multiple SSH keys
If you have multiple SSH keys setup, you need a config file to let git know which key should be used while cloning, forking, pulling or pushing changes.
- Open
C:\Users\<user>\.sshin your Windows explorer - Create a file with the name
config(with no extension) - Here in the example below, I had a
id_rsakey created for Bitbucket andid_ed25519for GitHub.
# ssh for win11 bitbucket
Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa
# ssh for win11 github
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_ed25519
If you have multiple SSH keys with the same host, update your config file accordingly.
Here is a reference link to the same. Link 1
Host gh_work
HostName github.com
IdentityFile ~/.ssh/id_rsa_work
Host gh_personal
HostName github.com
IdentityFile ~/.ssh/id_rsa_personal
⚠️ Changing the host name will also change the way you clone your repositories and the way you set remote.
git clone git@gh_work:gqc/foo.git
git clone git@gh_personal:foo/foo.git