git Key is already in use

版权声明:个人博客:yjz.life 欢迎前来交流!~本篇文章未经同意请勿转载! https://blog.csdn.net/m0_38072683/article/details/82939535

在远程创建仓库之后,添加SSH-key时,出现问题,说

Key is already in use

大致的意思就是这个key已经被占用。

我这时有一个疑惑,创建一个仓库需要一个key吗?

经过看官方文档发现了,这么一句话:

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

也就是说,这个错误原因是:该key被其他用户使用或被其他仓库使用

也就是说创建多个远程仓库之后,本地与远程连接的时候需要的KEY不一样。这个推理在官方文档中也找到了原话:

Once a key has been attached to one repository as a deploy key, it cannot be used on another repository. 

一个键作为部署的ssh key使用只能绑定一个仓库。

当然,官方也说了找到在哪个地方使用了该键:

ssh -T -ai ~/.ssh/id_rsa [email protected]
# Connect to GitHub using a specific ssh key
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

我发现我电脑上之前生成的SSH与仓库A关联,那么新建一个仓库都要重新生成一个,太麻烦了。

于是,我删除了仓库A的SSH-key。

在用户 Setting ---》 SSH and GPG keys ---》中将电脑上已有的key配置到了SSH keys上边,相当于配置了一个全局(github)的SSH-key。

接下来git push -u origin master。

成功!!!

当然了,如果你想配置多个不同仓库的SSH-key,比如你想配置一个github上的,一个gitlab上的。

你只需要再次用ssh-agent生成一个key,

然后新建一个txt文本,然后将名字后缀一起改成config,然后将必要信息填进去即可。

我只说了一个大概的思路,详细的传送们(戳我)

猜你喜欢

转载自blog.csdn.net/m0_38072683/article/details/82939535
今日推荐