如何在gitbash上的Windows计算机上生成多个SSH公钥并进行配置? [英] How to generate multiple SSH public key and configure those on windows machine from gitbash?
问题描述
让我们首先描述我所遇到的问题:
Let's first describe the problem that I've faced:
-
我有两台PC,其中一台是Windows计算机,另一台是Linux计算机.
I've two PC, one of them is the Windows machine and the other one is the Linux machine.
我想在这两台机器上生成两个SSH公共密钥.一个用于我的GitHub帐户,另一个用于我的GitLab帐户.
I want to generate two SSH public key on both of these machines. One is for my GitHub account and the other one is for my GitLab account.
我已经使用以下命令生成了公共SSH密钥,该密钥在我的Linux机器上可以正常使用,但在Windows机器上却不能.
I have used the following commands to generate the public SSH key which is perfectly work in my Linux machine but not in the Windows machine.
命令:
步骤1:生成SSH密钥
ssh-keygen
步骤2:将目录和文件名写入要保存SSH密钥的位置.
Step 2: Write the directory and file name where I want to save the SSH key.
[就我而言,我在下面插入了Windows路径]
[ For my case, I've inserted the windows path in below ]
/c/Users/PC_USER_NAME/.ssh/id_rsa_hub
第3步:从文件中获取公钥
cat ~/.ssh/id_rsa_hub.pub
这些步骤在我的Linux机器上可以正常工作,但是在Windows上,我看到了身份验证错误.如何配置SSH公钥?
These steps perfectly work on my Linux machine but on Windows, I saw the authentication error. How can I configure the SSH public key's?
推荐答案
对于Windows计算机,您必须再进行一次配置.只需按照下面的步骤操作(如果您使用的是Git Bash):
For the windows machine, you have to do one more configuration. Just follow the steps in below (if you're using the Git Bash):
- 转到.ssh目录
/c/Users/PC_USER_NAME/.ssh/
,单击鼠标右键并选择此处Git Bash" - 使用以下命令创建一个名为"config"的文件:
- Go to the .ssh directory
/c/Users/PC_USER_NAME/.ssh/
, click right mouse button and choose "Git Bash Here" - Create a file named "config" with the following command:
touch config
- 现在使用以下命令打开配置文件:
nano config
- 现在在配置文件中写入以下行
假设您已经创建了两个文件,分别为Github和id_rsa_lab
(分别为Github和id_rsa_lab
Let's assume you've created two files named id_rsa_hub
for Github and id_rsa_lab
for GitLab
# GITHUB
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_hub
# GITLAB
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_lab
这篇关于如何在gitbash上的Windows计算机上生成多个SSH公钥并进行配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!