PROBLEM
When trying to add a SSH key in GitHub, an error “Key is already in use” is thrown even though you signed into GitHub using a different user account.
SOLUTION
The error occurs when the same SSH key has been added to a different account. This typically happens when you already have an existing personal GitHub account and you are trying to use the same SSH key in a work-related GitHub Enterprise account.
The fix is to use a new SSH key. When generating the SSH key using ssh-keygen, remember NOT to override the existing ~/.ssh/id_rsa. Rather, use a different file path, such as ~/.ssh/id_rsa_github_enterprise.
To ensure seamless integration when doing a git clone, add the following configuration in ~/.ssh/config.
Host github.com
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-enterprise.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github_enterprise
The first block ensures it doesn’t break the existing GitHub connectivity using the default SSH key.
The second block allows a different SSH key to be used when connecting to GitHub. In order to leverage this configuration, the host name needs to be tweaked when doing a git clone.
# Don't do this because this will use ~/.ssh/id_rsa
git clone [email protected]:shitty_user/shitty_repo.git
# Do this instead to use the new SSH key
git clone [email protected]:shitty_user/shitty_repo.git
Leave a Reply