我有两个Gitlab账户。在我的旧帐户上,我在我的计算机上添加了一个位于~/.ssh/id_rsa.pub中的ssh键。
现在,我想为我的新Gitlab帐户添加另一个ssh键。如何在不发生ssh键冲突的情况下做到这一点?
发布于 2018-01-14 09:25:16
我推荐第二把钥匙,现在不用密码:
ssh-keygen -t rsa -C "your_email@example.com" -P "" -q -f ~/.ssh/gitlab_rsa这将创建(没有任何提示) ~/.ssh/gitlab_rsa (私钥)和~/.ssh/gitlab_rsa.pub (公钥)
你需要第二个GitLab帐户的公钥。
导航到“配置文件设置”中的“SSH键”选项卡。粘贴你的钥匙在‘键’部分,并给它一个相关的‘标题’。
然后添加一个具有以下内容的~/.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>,并将使用您的第二个键。
发布于 2018-01-14 09:18:33
生成一个新的密钥对,它具有:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"它将要求您输入密钥文件的名称:
Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]选择一些不同的东西,如/Users/you/..ssh/gitlab_rsa
然后,当您需要它时,将这个密钥添加到ssh代理中:
ssh-add ~/.ssh/gitlab_rsa如果您想要永久访问,可以使用以下方式编辑~/.ssh/config文件:
Host gitlab_rsa
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile /home/<you>/.ssh/gitlab_rsa有关详细信息,请参阅此文章。
发布于 2018-01-14 09:29:09
您需要创建文件~/.ssh/config来定义每个域应该使用哪个键。
使用nano创建该文件并粘贴您的配置:
nano ~/.ssh/config并增加:
Host your-gitlab.com
HostName your-gitlab.com
IdentityFile ~/.ssh/your-gitlab-privkeyhttps://stackoverflow.com/questions/48248144
复制相似问题