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,而後將必要信息填進去便可。

我只說了一個大概的思路,詳細的傳送們(戳我)

相關文章
相關標籤/搜索