Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

Error: Key already in use

This error occurs when you try to add 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 the ssh command. Use the -i flag to provide the path to the key you want to check:

$ ssh -T -ai ~/.ssh/id_rsa git@hostname
# Connect to your GitHub Enterprise Server instance using a specific ssh key
> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.

The username in the response is the account on your GitHub Enterprise Server instance that the key is currently attached to. If the response looks something like "username/repo", the key has been attached to a repository as a deploy key.

To force SSH to use only the key provided on the command line, use -o to add the IdentitiesOnly=yes option:

$ ssh -v -o "IdentitiesOnly=yes" -i ~/.ssh/id_rsa git@hostname

Fixing the issue

To resolve the issue, first remove the key from the other account or repository and then add 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 and generate 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, see "Managing deploy keys."