Error: Key already in use
This error occurs when you try toadd a key that's already been added to another account or repository.
Finding where the key has been used
To determine where the key has already been used, open a terminal and type thessh
command. Use the-i
flag to provide the path to the key you want to check:
$ssh -T -ai ~/.ssh/id_rsa git@github.com#Connect to GitHub.com using a specific ssh key>Hi USERNAME! You've successfully authenticated, but GitHub does not>provide shell access.
Theusername in the response is the account on GitHub.com that the key is currently attached to. If the response looks something like "username/repo", the key has been attached to a repository as adeploy key.
To force SSH to use only the key provided on the command line, use-o
to add theIdentitiesOnly=yes
option:
ssh -v -o "IdentitiesOnly=yes" -i ~/.ssh/id_rsa git@github.com
Fixing the issue
To resolve the issue, first remove the key from the other account or repository and thenadd it to your account.
If you don't have permissions to transfer the key, and can't contact a user who does, remove the keypair andgenerate a brand new one.
Deploy keys
Once a key has been attached to one repository as a deploy key, it cannot be used on another repository. If you're running into this error while setting up deploy keys, seeManaging deploy keys.