如何为我的新gitlab帐户生成新的ssh-key?

Ben*_*ari 6 git ssh-keys gitlab

我有两个Gitlab帐户.在我的旧帐户中,我添加了一个位于我的计算机上的ssh密钥~/.ssh/id_rsa.pub.

现在我想为我的新Gitlab帐户添加另一个ssh-key.如果没有ssh-keys冲突,我该怎么做?

Von*_*onC 12

我建议使用第二个密钥,现在没有密码:

ssh-keygen -t rsa -C "your_email@example.com" -P "" -q -f ~/.ssh/gitlab_rsa
Run Code Online (Sandbox Code Playgroud)

这将创建(没有任何提示)~/.ssh/gitlab_rsa(私钥)和~/.ssh/gitlab_rsa.pub(公钥)

您需要将第二个gitlab_rsa.pub公钥注册到第二个GitLab帐户.

导航到"配置文件设置"中的"SSH密钥"选项卡.将您的密钥粘贴到"密钥"部分,并为其指定相关的"标题".

然后添加一个~/.ssh/config文件:

Host gitlab_rsa
    HostName gitlab.com
    User git
    PreferredAuthentications publickey
    IdentityFile /home/<you>/.ssh/gitlab_rsa
Run Code Online (Sandbox Code Playgroud)

最后,您可以使用以下命令克隆任何GitLab repo作为您的第二个身份:

git clone gitlab_rsa:<yourSecondAccount>/<yourRepo.git>
Run Code Online (Sandbox Code Playgroud)

这将自动替换git@gitlab.com:<yourSecondACcount>/<yourRepo.git>,并将使用您的第二个密钥.