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

标签 git gitlab ssh-keys

我有两个 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/

相关文章:

git - 我如何在git中切换分支?

git - windows上的Git Bash如何退出 'git diff'的结果?

具有文件名支持的 Git bash-completion?

GitLab:无法 fork 我自己的项目

javascript - Puttygen 和 NodeJS 上生成的 RSA key 的长度不同

git - 不小心在 git 中运行命令 checkout -B "branchname"

git - Cent os bash 无法识别选项 --adduser 命令上的系统

ruby-on-rails - 清除 GitLab 中的所有 Assets

github - 从上游获取时,github 上的权限被拒绝(公钥)

git - 如何在同一台笔记本电脑的 github 帐户上再次使用相同的 ssh 公钥?