我有两个 Gitlab 帐户。在我的旧帐户 上,我添加了一个ssh key ,它位于我计算机上的~/.ssh/id_rsa.pub
中。
现在我想为我的新 Gitlab 帐户添加另一个 ssh-key。如何在没有 ssh key 冲突的情况下执行此操作?
最佳答案
我会推荐第二个 key ,现在没有密码:
ssh-keygen -t rsa -C "your_email@example.com" -P "" -q -f ~/.ssh/gitlab_rsa
这将创建(没有任何提示)~/.ssh/gitlab_rsa
(私钥)和~/.ssh/gitlab_rsa.pub
(公钥)
您需要register that second gitlab_rsa.pub
public key to your second GitLab account .
Navigate to the 'SSH Keys' tab in your 'Profile Settings'. Paste your key in the 'Key' section and give it a relevant 'Title'.
然后添加一个~/.ssh/config
文件:
Host gitlab_rsa
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile /home/<you>/.ssh/gitlab_rsa
最后,您可以克隆任何 GitLab 存储库作为您的第二身份:
git clone gitlab_rsa:<yourSecondAccount>/<yourRepo.git>
这将自动替换为 git@gitlab.com:<yourSecondACcount>/<yourRepo.git>
并将使用您的第二个 key 。
关于git - 如何为我的新 gitlab 帐户生成新的 ssh-key?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48248144/