git Key is already in use

在远程建立仓库以后,添加SSH-key时,出现问题,说git

Key is already in usegithub

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

我这时有一个疑惑,建立一个仓库须要一个key吗?bash

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

 

Error: Key already in use

This error occurs when you try to add a key that's already been added to another account or repositoryide

 

也就是说,这个错误缘由是:该key被其余用户使用或被其余仓库使用gitlab

也就是说建立多个远程仓库以后,本地与远程链接的时候须要的KEY不同。这个推理在官方文档中也找到了原话:code

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

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

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

ssh -T -ai ~/.ssh/id_rsa git@github.com
# 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,而后将必要信息填进去便可。

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

相关文章
相关标签/搜索