git 如何为我的新 gitlab 帐户生成新的 ssh 密钥?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48248144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I generate new ssh-key for my new gitlab account?
提问by Benyamin Jafari
I have two Gitlab accounts. On my old accountI added an ssh-keythat is located in ~/.ssh/id_rsa.pub
on my computer.
我有两个 Gitlab 帐户。在我的旧帐户中,我添加了一个位于我计算机上的ssh 密钥~/.ssh/id_rsa.pub
。
Now I want to add another ssh-keyfor my new Gitlab account. How do I do this without having the ssh-keys conflict?
现在我想为我的新 Gitlab 帐户添加另一个ssh 密钥。如何在没有 ssh 密钥冲突的情况下执行此操作?
回答by VonC
I would recommend a second key, for now without passphrase:
我会推荐第二个密钥,现在没有密码:
ssh-keygen -t rsa -C "[email protected]" -P "" -q -f ~/.ssh/gitlab_rsa
That will create (without any prompt) ~/.ssh/gitlab_rsa
(private key) and ~/.ssh/gitlab_rsa.pub
(public key)
这将创建(没有任何提示)~/.ssh/gitlab_rsa
(私钥)和~/.ssh/gitlab_rsa.pub
(公钥)
You need to register that second gitlab_rsa.pub
public key to your second GitLab account.
您需要将第二个gitlab_rsa.pub
公钥注册到您的第二个 GitLab 帐户。
Navigate to the 'SSH Keys' tab in your 'Profile Settings'. Paste your key in the 'Key' section and give it a relevant 'Title'.
导航到“配置文件设置”中的“SSH 密钥”选项卡。将您的密钥粘贴到“密钥”部分并为其指定一个相关的“标题”。
Then add a ~/.ssh/config
file with:
然后添加一个~/.ssh/config
文件:
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:
最后,您可以克隆任何 GitLab 存储库作为您的第二个身份:
git clone gitlab_rsa:<yourSecondAccount>/<yourRepo.git>
That will be replaced automatically with [email protected]:<yourSecondACcount>/<yourRepo.git>
and will use your second key.
这将被自动替换[email protected]:<yourSecondACcount>/<yourRepo.git>
,并将使用您的第二把钥匙。
回答by Ortomala Lokni
Generate a new key pair with:
生成一个新的密钥对:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
It will ask you to enter a name for the key file:
它会要求您输入密钥文件的名称:
Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
Choose something different such as /Users/you/.ssh/gitlab_rsa
选择不同的东西,例如 /Users/you/.ssh/gitlab_rsa
Then when you need it add this key to your ssh-agent with:
然后,当您需要时,将此密钥添加到您的 ssh-agent 中:
ssh-add ~/.ssh/gitlab_rsa
If you want a permanent access you can edit your ~/.ssh/config
file with:
如果您想要永久访问权限,您可以使用以下命令编辑您的~/.ssh/config
文件:
Host gitlab_rsa
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile /home/<you>/.ssh/gitlab_rsa
Refer to this articlefor further details.
有关更多详细信息,请参阅本文。
回答by Elena Bonet
You need to create the file ~/.ssh/config
to define which key should use for every domain.
您需要创建文件~/.ssh/config
来定义每个域应该使用哪个密钥。
Create that file with nano and paste your configuration:
使用 nano 创建该文件并粘贴您的配置:
nano ~/.ssh/config
And add:
并添加:
Host your-gitlab.com
HostName your-gitlab.com
IdentityFile ~/.ssh/your-gitlab-privkey
回答by Durga prasad
Generate SSH please follow below steps.
生成 SSH 请按照以下步骤操作。
Open Git Bash on you machine
在你的机器上打开 Git Bash
Enter the below command to genarate
输入以下命令生成
ssh-keygen -t rsa -b 4096 -C "[email protected]"
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Generating public/private rsa key pair. Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):Press enter Enter passphrase (empty for no passphrase): Type a passphrase Enter same passphrase again: Type passphrase again
生成公钥/私钥 rsa 密钥对。输入要保存密钥的文件 (/c/Users/you/.ssh/id_rsa):按 Enter Enter passphrase (empty for no passphrase):输入密码再次输入相同密码:再次输入密码
Once enter the confirm passphrase, will get confirmation message.
输入确认密码后,将收到确认消息。
go to the gitpair.pub file location and right click open with notepad. copy the code and past the in the below text box, your email will pick automatically in the title box. then click add key.
转到 gitpair.pub 文件位置并右键单击用记事本打开。复制代码并粘贴在下面的文本框中,您的电子邮件将在标题框中自动选择。然后单击添加密钥。