1. 程式人生 > >git Key is already in use

git Key is already in use

在遠端建立倉庫之後,新增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,然後將必要資訊填進去即可。

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