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

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

问题描述

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

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.

现在我想为我的新 Gitlab 帐户添加另一个 ssh-key.如何在没有 ssh-keys 冲突的情况下执行此操作?

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

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

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

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

You need to register that second gitlab_rsa.pub public key to your second GitLab account.

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

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 文件:

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

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

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

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

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

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

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

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

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