Skip to main content

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.

  1. Generate SSH Key
  2. Add SSH Key to your GitHub account

Bitbucket

To setup SSH for Bitbucket, please follow the instructions mentioned over here.

  1. Generate and Add SSH Key

⚠️ 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.

  1. Open C:\Users\<user>\.ssh in your Windows explorer
  2. Create a file with the name config (with no extension)
  3. Here in the example below, I had a id_rsa key created for Bitbucket and id_ed25519 for 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.

info

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