如何为新的gitlab帐户生成新的ssh密钥? [英] How do I generate a new ssh-key for my new gitlab account?

查看:92
本文介绍了如何为新的gitlab帐户生成新的ssh密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

现在,我想为我的新Gitlab帐户添加另一个 ssh-key .在没有ssh-key冲突的情况下如何做到这一点?

解决方案

我建议使用第二个密钥,暂时不要输入密码:

  ssh-keygen -t rsa -C"your_email@example.com" -P" -q -f〜/.ssh/gitlab_rsa 

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

您需要注册该秒 gitlab_rsa.pub 到您的第二个GitLab帐户的公共密钥.

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

然后使用以下命令添加〜/.ssh/config 文件:

 主机gitlab_rsa主机名gitlab.com用户gitPreferredAuthentications公钥IdentityFile/home/<you>/.ssh/gitlab_rsa 

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

  git clone gitlab_rsa:< yourSecondAccount>/< yourRepo.git> 

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

I have two Gitlab accounts. On my old account I added an ssh-key that is located in ~/.ssh/id_rsa.pub on my computer.

Now I want to add another ssh-key for my new Gitlab account. How do I do this without having the ssh-keys conflict?

解决方案

I would recommend a second key, for now without passphrase:

ssh-keygen -t rsa -C "your_email@example.com" -P "" -q -f ~/.ssh/gitlab_rsa

That will create (without any prompt) ~/.ssh/gitlab_rsa (private key) and ~/.ssh/gitlab_rsa.pub (public key)

You need to 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'.

Then add a ~/.ssh/config file with:

Host gitlab_rsa
    HostName gitlab.com
    User git
    PreferredAuthentications publickey
    IdentityFile /home/<you>/.ssh/gitlab_rsa

Finally, you can clone any GitLab repo as your second identity with:

git clone gitlab_rsa:<yourSecondAccount>/<yourRepo.git>

That will be replaced automatically with git@gitlab.com:<yourSecondACcount>/<yourRepo.git> and will use your second key.

这篇关于如何为新的gitlab帐户生成新的ssh密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆