您需要在 a 中声明不同的 ssh 密钥~/.ssh/config
文件,正如我在“如何管理 ~/.ssh 目录中的多个 ssh 密钥"
我建议不要使用键的默认名称,而是:
~/.ssh/proj1
~/.ssh/proj1.pub
~/.ssh/proj2
~/.ssh/proj2.pub
然后有一个~/.ssh/config
like:
Host ghproj1
User git
Hostname github.com
IdentityFile ~/.ssh/proj1
IdentitiesOnly yes
Host ghproj2
User git
Hostname github.com
IdentityFile ~/.ssh/proj2
IdentitiesOnly yes
您需要更改两个存储库中的原始 url:
cd /path/to/cloned/proj1
git remote set-url origin ghproj1:yourProject1
cd /path/to/cloned/proj2
git remote set-url origin ghproj1:yourProject2
更多信息请访问:
- "如何临时更改git ssh用户进行远程推送?"
- "在终端上切换 GitHub 帐户时遇到问题"
一个像这样的网址ghproj1:yourProject1
是一个 ssh ,它将显式使用您在中指定的密钥~/.ssh/config
为了ghproj1
entry.
在OP的情况下(回答如下),正确的网址是:
~/.ssh/id_recaprojekt
Note: 您需要指定私钥的路径(private、not public、not.pub
)
cd /path/to/cloned/plastickychirurg
git remote set-url origin plastickychirurg:michalfeher/plastickychirurg.git
cd /path/to/cloned/recaprojekt
git remote set-url origin recaprojekt:michalfeher/recaprojekt.git
请注意,我在主机条目中添加了“主机名”。
~/.ssh/config 文件中这些条目的全部想法是不要(重复not) put git
or github.com
在 url 中(由与每个条目关联的项目为您完成):
So:
[email protected]:michalfeher/recaprojekt.git
是相同的:
recaprojekt:michalfeher/recaprojekt.git
除了第二个 url 将使用 ssh 密钥